├── .gitignore ├── Algo_DS_Code_Library ├── 01 │ ├── 2SAT LOJ 1407.cpp │ ├── Aho Corasick without Struct + logn decomposition CF 710F .cpp │ ├── Aho Corasick.cpp │ ├── Articulation, Bridge, BCC.cpp │ ├── BIT.cpp │ ├── BS in descending array.cpp │ ├── BigInt Jan bhai.cpp │ ├── Binary Search.cpp │ ├── CF │ │ ├── 337D. Book of Evil.cpp │ │ ├── BPM + NT 498C. Array and Operations.cpp │ │ ├── DSU + BFS 455C. Civilization.cpp │ │ └── FFT + BigMod 632E. Thief in a Shop.cpp │ ├── Convex Hull (Graham Scan).cpp │ ├── Convex Hull Trick OWN.cpp │ ├── Convex Hull Trick.cpp │ ├── DSU.cpp │ ├── Dinic.cpp │ ├── Extended Euclid.cpp │ ├── FFT.cpp │ ├── Fast IO.cpp │ ├── Gaussian Elem. LOJ1272 Maximum Subset Sum.cpp │ ├── HLD range update single query GSS7 - Can you answer these queries VII.cpp │ ├── HLD single update range query.cpp │ ├── Hashing.cpp │ ├── Histogram GREEDY.cpp │ ├── KMP - A Problem.cpp │ ├── KMP.cpp │ ├── LCA.cpp │ ├── LOJ │ │ ├── 1018 - Brush (IV) 2.cpp │ │ ├── 1048 - Conquering Keokradong .cpp │ │ ├── 1061 - N Queen Again.cpp │ │ ├── 1073 - DNA Sequence.cpp │ │ ├── 1081 - Square Queries.cpp │ │ ├── 1086 - Jogging Trails.cpp │ │ ├── 1087 - Diablo new.cpp │ │ ├── 1097 - Lucky Number.cpp │ │ ├── 1103 - Castle Walls.cpp │ │ ├── 1110 - An Easy LCS 2.cpp │ │ ├── 1117 helping cicada.c │ │ ├── 1120 - Rectangle Union ORS.cpp │ │ ├── 1126 - Building Twin Towers.cpp │ │ ├── 1127 - Funny Knapsack.cpp │ │ ├── 1144 - Ray Gun PIE.cpp │ │ ├── 1147 - Tug of War BITMASK.cpp │ │ ├── 1156 - Jumping Frogs DINIC.cpp │ │ ├── 1160 - Discovering Paths in Grid.cpp │ │ ├── 1177 - Angry Programmer FLOW BFS.cpp │ │ ├── 1180 - Software Company ITERATIVE.cpp │ │ ├── 1209 - Strange Voting BPM.cpp │ │ ├── 1240 - Point Segment Distance (3D) TERNARY.cpp │ │ ├── 1267 - Points in Rectangle (II).cpp │ │ ├── 1268 - Unlucky Strings.cpp │ │ ├── 1282 - Leading and Trailing.cpp │ │ ├── 1295 - Lighting System Design.cpp │ │ ├── 1306 - Solutions to an Equation.cpp │ │ ├── 1330 - Binary Matrix DINIC.cpp │ │ ├── 1334 - Genes in DNA.cpp │ │ ├── 1356 - Prime Independence HOPCROFT.cpp │ │ ├── 1397 - Sudoku Solver PRUNING.cpp │ │ ├── 1406 - Assassin`s Creed.cpp │ │ ├── 1428 - Melody Com.cpp │ │ └── Problem Details.txt │ ├── MO.cpp │ ├── Matrix Expo.cpp │ ├── Min Cost Max Flow.cpp │ ├── Next Palindrome.cpp │ ├── Number Theory.cpp │ ├── ORS (Segtree) Rectangle Union .cpp │ ├── PBDS.cpp │ ├── Pick Theorem LOJ1418.cpp │ ├── Segment Tree (2D) WINDVANE.cpp │ ├── Segment Tree (Persistant) MKTHNUM.cpp │ ├── Sibling DP.cpp │ ├── Sliding Window RMQ.cpp │ ├── SquareRoot Decomposition CHEFEXQ .cpp │ ├── Stable Marriage LOJ.cpp │ ├── String.cpp │ ├── Suffix Array nLogn.cpp │ ├── TEMPLATE.cpp │ ├── Totient Sieve.cpp │ ├── Totient direct.cpp │ ├── Trie Array.cpp │ ├── Trie Linked List.cpp │ └── UVA │ │ └── CHT(min) + N^2 12524 - Arranging Heaps.cpp ├── 02 │ ├── 1171 - Knights in Chessboard (II) HOPCROFT.cpp │ ├── CHT + Segment Tree, CF 91E. Igloo Skyscraper.cpp │ ├── Centroid Decom SPOJ QTREE5 - Query on a tree V.cpp │ ├── Centroid Decomposition.cpp │ ├── D&Q Opt HackerRank [IOI] Guardians of the Lunatics.cpp │ ├── FWHT.cpp │ ├── Knuth's Opt SPOJ BRKSTRNG - Breaking String.cpp │ ├── LOJ 1218-Multiple-Free-Subset - MATCHING, SOLUTION PRINT (smallest).cpp │ ├── LOJ 1429 - Assaissin's Creed 2 - SCC, GENERAL PATH COVER, MATCHING.cpp │ ├── Suffix Array (Morris) UVA 10234 - Frequent Substring.cpp │ └── map.cpp ├── 03 │ ├── 2D Segment Tree (Net).cpp │ ├── All Divisors Sieve.cpp │ ├── BPM (Lexicographic solution) LOJ1218-Multiple-Free-Subset.cpp │ ├── CF343D. Water Tree.cpp │ ├── Centroid Decom + BST construction in nlogn + BST Maintanance.cpp │ ├── DINIC + SolutionPrint CF546E. Soldier and Traveling.cpp │ ├── DSU on Tree (HLD Style).cpp │ ├── DSU on Tree.cpp │ ├── Dijkstra with edges in Segment Tree CF786B. Legacy.cpp │ ├── Dominator Tree (Tanuj).cpp │ ├── Dominator Tree.cpp │ ├── FFT Hamming Distance 101667H Rock Paper Scissors.cpp │ ├── GAUSS LOJ 1288 - Subsets Forming Perfect Squares.cpp │ ├── GT Multiple games 455B. A Lot of Games.cpp │ ├── Hackenbush (on wighted Tree) LOJ1355 - Game of CS.cpp │ ├── Int To Excel.cpp │ ├── Prime Factorization in logn.cpp │ ├── ROPE HackerRank - Array and Simple Queries.cpp │ ├── SegTree with 2 types of range updates.cpp │ ├── Segmented Sieve.cpp │ ├── Z.cpp │ └── a^b numbers in [l,r] CF 955C. Sad powers.cpp ├── 04 │ ├── 3D Geo Library (Sadman).cpp │ ├── Cen. Decom. (child info keeping necessary) - CFGYM 100570F. Tree Query.cpp │ ├── Centroid Decom (no update approach) - UVaLive 6900 - Road Repair.cpp │ ├── LIS Binary search.cpp │ ├── LIS Set.cpp │ ├── Maximum Manhattan distance.cpp │ └── SegTree - Min Man dis. in range codechef MDIST - Devu and Manhattan Distance.cpp └── rantree.cpp ├── Codeforces ├── Gym │ ├── 100112J Juice.cpp │ ├── 100283A. Rasheda And The Zeriba.cpp │ ├── 100283B. Egyptian Roads Construction.cpp │ ├── 100570F. Tree Query.cpp │ ├── 100589F. Count Ways.cpp │ ├── 100685J. Just Another Disney Problem.cpp │ ├── 100820G. Racing Gems.cpp │ ├── 100886H. Biathlon 2.0.cpp │ ├── 101021A. Guess the Number.cpp │ ├── 101505F Tree Stands.cpp │ ├── 101667H. Rock Paper Scissors.cpp │ ├── 101853E. Maximum Sum.cpp │ ├── rantree.cpp │ └── tree query brute.cpp ├── Practice │ ├── 001.c │ ├── 002.c │ ├── 003.c │ ├── 005C. Longest Regular Bracket Sequence.cpp │ ├── 005C. longest... 2.cpp │ ├── 006C. Alice, Bob and Chocolate.cpp │ ├── 009C. Hexadecimal's Numbers.cpp │ ├── 018C. Stripe.cpp │ ├── 1003D. Coins and Queries.cpp │ ├── 1006F. Xor-Paths.cpp │ ├── 1015E2. Stars Drawing (Hard Edition).cpp │ ├── 1016D. Vasya And The Matrix.cpp │ ├── 101B. Buses.cpp │ ├── 1031C. Cram Time.cpp │ ├── 1033C. Permutation Game.cpp │ ├── 1033D. Divisors.cpp │ ├── 1042D. Petya and Array.cpp │ ├── 1043F. Make It One.cpp │ ├── 1060 - nth Permutation.cpp │ ├── 1077E. Thematic Contests.cpp │ ├── 1077F naive.cpp │ ├── 1077F rafi.cpp │ ├── 1077F2. Pictures with Kittens (hard version).cpp │ ├── 1093G. Multidimensional Queries.cpp │ ├── 109A. Lucky Sum of Digits.cpp │ ├── 109B. Lucky Probability.cpp │ ├── 109C. Lucky Tree.cpp │ ├── 112A. Petya and Strings.py │ ├── 112A.cpp │ ├── 113B. Petr#.cpp │ ├── 1154 - Penguins.cpp │ ├── 115A. Party.cpp │ ├── 1172 - Krypton Number System.cpp │ ├── 118A. String Task.py │ ├── 118A.cpp │ ├── 118D.cpp │ ├── 124A.c │ ├── 126B. Password.cpp │ ├── 127D. Password.cpp │ ├── 128B. String.cpp │ ├── 1291 Real Life Traffic again new.cpp │ ├── 133A.cpp │ ├── 137C. History.cpp │ ├── 144A.cpp │ ├── 148D. Bag of mice.cpp │ ├── 149C. Division into Teams.cpp │ ├── 150B. Quantity of Strings.cpp │ ├── 152C. Pocket Book.cpp │ ├── 154B. Colliders.cpp │ ├── 158A.cpp │ ├── 15C. Industrial Nim.cpp │ ├── 160C. Find Pair.cpp │ ├── 161D. Distance in Tree CENTROID.cpp │ ├── 161D. Distance in Tree.cpp │ ├── 165C. Another Problem on Strings.cpp │ ├── 166E exp.cpp │ ├── 166E. Tetrahedron iterative.cpp │ ├── 166E. Tetrahedron.cpp │ ├── 178B3. Greedy Merchants.cpp │ ├── 17B. Hierarchy.cpp │ ├── 182D. Common Divisors.cpp │ ├── 191C. Fools and Roads.cpp │ ├── 197A. Plate Game.cpp │ ├── 1A.c │ ├── 204B. Little Elephant and Cards.cpp │ ├── 208D. Prizes, Prizes, more Prizes.cpp │ ├── 208E. Blood Cousins DSU.cpp │ ├── 208E. Blood Cousins.cpp │ ├── 217A. Ice Skating.cpp │ ├── 219C. Color Stripe.cpp │ ├── 219D. Choosing Capital for Treeland.cpp │ ├── 220A. Little Elephant and Problem 2.cpp │ ├── 220A. Little Elephant and Problem.cpp │ ├── 222E. Decoding Genome.cpp │ ├── 224B. Array.cpp │ ├── 225C. Barcode.cpp │ ├── 226B. Naughty Stone Piles.cpp │ ├── 230B. T-primes.cpp │ ├── 231A.cpp │ ├── 242C. King's Path.cpp.cpp │ ├── 242E. XOR on Segment.cpp │ ├── 245H. Queries for Number of Palindromes.cpp │ ├── 246E. Blood Cousins Return.cpp │ ├── 251A. Points on Line.cpp │ ├── 253B. Physics Practical.cpp │ ├── 255C. Barcode.cpp │ ├── 257B. Playing Cubes.cpp │ ├── 258A. Little Elephant and Bits.cpp │ ├── 264A. Escape from Stones manual link list.cpp │ ├── 264A. Escape from Stones.cpp │ ├── 266B. Queue at the School.cpp │ ├── 268B.c │ ├── 271D. Good Substrings.cpp │ ├── 272D. Dima and Two Sequences.cpp │ ├── 275B. Convex Shape.cpp │ ├── 276C. Little Girl and Maximum Sum efficient.cpp │ ├── 276C. Little Girl and Maximum Sum.cpp │ ├── 279C. Ladder.cpp │ ├── 280C. Game on Tree.cpp │ ├── 281A.cpp │ ├── 282D. Yet Another Number Game ITERATIVE DP + RMQ.cpp │ ├── 282D. Yet Another Number Game.cpp │ ├── 283A. Cows and Sequence (2).cpp │ ├── 283A. Cows and Sequence.cpp │ ├── 292E. Copying Data.cpp │ ├── 294C. Shaass and Lights.cpp │ ├── 295A. Greg and Array.cpp │ ├── 295C. Greg and Friends.cpp │ ├── 2B. The least round way.cpp │ ├── 300C. Beautiful Numbers.cpp │ ├── 318A.c │ ├── 319B. Psychos in a Line.c │ ├── 319B. Psychos in a Line.cpp │ ├── 319B. Psychos in a Line.py │ ├── 319C. Kalila and Dimna in the Logging Industry.cpp │ ├── 321B. Ciel and Duel GREEDY.cpp │ ├── 321B. Ciel and Duel.cpp │ ├── 321C. Ciel the Commander.cpp │ ├── 321E. Ciel and Gondolas.cpp │ ├── 327C. Magic Five.cpp │ ├── 337C. Quiz.cpp │ ├── 337D. Book of Evil.cpp │ ├── 339A. Helpful Maths.py │ ├── 339B. Xenia and Ringroad.cpp │ ├── 339C. Xenia and Weights.cpp │ ├── 339D. Xenia and Bit Operations.cpp │ ├── 341D. Iahub and Xors.cpp │ ├── 342E. Xenia and Tree.cpp │ ├── 343D. Water Tree.cpp │ ├── 346B. Lucky Common Subsequence.cpp │ ├── 346C Brute.cpp │ ├── 348A. Mafia.cpp │ ├── 348C arg007.cpp │ ├── 348C. Subset Sums.cpp │ ├── 349B. Color the Fence.cpp │ ├── 350C. Bombs.cpp │ ├── 354A. Vasya and Robot.cpp │ ├── 358D. Dima and Hares.cpp │ ├── 359D. Pair of Numbers.cpp │ ├── 363C. Fixing Typos.cpp │ ├── 367B. Sereja ans Anagrams.cpp │ ├── 369C. Valera and Elections.cpp │ ├── 371C. Hamburgers 2.cpp │ ├── 371C. Hamburgers.cpp │ ├── 371D. Vessels.cpp │ ├── 371D. Vessels.py │ ├── 372A. Counting Kangaroos is Fun.cpp │ ├── 374C. Inna and Dima.cpp │ ├── 375A. Divisible by Seven.cpp │ ├── 375D. Tree and Queries.cpp │ ├── 377A. Maze.cpp │ ├── 380C. Sereja and Brackets.cpp │ ├── 382C. Arithmetic Progression.cpp │ ├── 383C. Propagating tree.cpp │ ├── 383D. Antimatter.cpp │ ├── 385 tle 17.cpp │ ├── 385C. Bear and Prime Numbers.cpp │ ├── 388A. Fox and Box Accumulation.cpp │ ├── 388B. Fox and Minimal path.cpp │ ├── 401A.c │ ├── 401C. Team.cpp │ ├── 401D. Roman and Numbers.cpp │ ├── 404C. Restore Graph.cpp │ ├── 407A. Triangle.cpp │ ├── 414A. Mashmokh and Numbers.cpp │ ├── 414B. Mashmokh and ACM.cpp │ ├── 416E. President's Path.cpp │ ├── 424C. Magic Formulas.cpp │ ├── 427C. Checkposts.cpp │ ├── 429D. Babaei and Birthday Cake.cpp │ ├── 430C. Ilya And The Tree.cpp │ ├── 431C. k-Tree.cpp │ ├── 432D. Prefixes and Suffixes.cpp │ ├── 437D. The Child and Zoo.cpp │ ├── 438D. The Child and Sequence.cpp │ ├── 441C. Valera and Tubes.cpp │ ├── 448C. Painting Fence.cpp │ ├── 448D. Multiplication Table.cpp │ ├── 449B. Jzzhu and Cities NEW.cpp │ ├── 449B. Jzzhu and Cities.cpp │ ├── 451D. Count Good Substrings.cpp │ ├── 453B. Little Pony and Harmony Chest.cpp │ ├── 455A. Boredom.cpp │ ├── 455B. A Lot of Games.cpp │ ├── 455C. Civilization.cpp │ ├── 457A. Golden System.cpp │ ├── 459C. Pashmak and Buses.cpp │ ├── 460B. Little Dima and Equation.cpp │ ├── 463C. Gargari and Bishops.cpp │ ├── 463D. Gargari and Permutations.cpp │ ├── 464A. No to Palindromes! recursion.cpp │ ├── 464A. No to Palindromes!.cpp │ ├── 466C - Number of Ways.cpp │ ├── 466D. Increase Sequence.cpp │ ├── 466D. Increase Sequence.py │ ├── 467A.c │ ├── 467A.cpp │ ├── 467B. Fedor and New Game.cpp │ ├── 468B. Two Sets.cpp │ ├── 471D. MUH and Cube Walls.cpp │ ├── 474C. Captain Marmot.cpp │ ├── 474D - Flowers.cpp │ ├── 474D - flowers iterative.cpp │ ├── 474E. Pillars.cpp │ ├── 474F. Ant colony.cpp │ ├── 476B - Dreamoon and WiFi.cpp │ ├── 478B. Random Teams.CPP │ ├── 478C. Table Decorations.cpp │ ├── 478D. Red-Green Towers ITERATIVE.cpp │ ├── 478D. Red-Green Towers brute.cpp │ ├── 478D. Red-Green Towers.cpp │ ├── 479C. Exams.cpp │ ├── 479D. Long Jumps.cpp │ ├── 483B. Friends and Presents.cpp │ ├── 485A. Factory.cpp │ ├── 486C. Palindrome Transformation.cpp │ ├── 486D. Valid Sets WA.cpp │ ├── 486D. Valid Sets.cpp │ ├── 486E. LIS of Sequence.cpp │ ├── 489C - Given Length and Sum of Digits.cpp │ ├── 489D. Unbearable Controversy of Being.cpp │ ├── 490B. Queue.cpp │ ├── 490C. Hacking Cypher.cpp │ ├── 493C. Vasya and Basketball.cpp │ ├── 493D. Vasya and Chess.cpp │ ├── 496C. Removing Columns.cpp │ ├── 498A. Crazy Town.cpp │ ├── 498C. Array and Operations.cpp │ ├── 4A. Watermelon.py │ ├── 500D. New Year Santa Network.cpp │ ├── 505C. Mr. Kitayuta, the Treasure Hunter.cpp │ ├── 507B. Amr and Pins.cpp │ ├── 508C. Anya and Ghosts.cpp │ ├── 509C. Sums of Digits.cpp │ ├── 510D. Fox And Jumping.cpp │ ├── 510E. Fox And Dinner.cpp │ ├── 514D. R2D2 and Droid Army.cpp │ ├── 515A.cpp │ ├── 519C. A and B and Team Training.cpp │ ├── 519E. A and B and Lecture Rooms.cpp │ ├── 535D. Tavas and Malekas.cpp │ ├── 53C. Little Frog.cpp │ ├── 540D. Bad Luck Island.cpp │ ├── 545C. Woodcutters.cpp │ ├── 546E. Soldier and Traveling.cpp │ ├── 550A. Two Substrings.cpp │ ├── 550C. Divisibility by Eight.cpp │ ├── 551C. GukiZ hates Boxes.cpp │ ├── 552C. Vanya and Scales.cpp │ ├── 552D. Vanya and Triangles.cpp │ ├── 570D. Tree Requests DSU.cpp │ ├── 570D. Tree Requests.cpp │ ├── 570E. Pig and Palindromes.cpp │ ├── 578B. Or Game.cpp │ ├── 579D. Or Game.cpp │ ├── 57C. Array Brute.cpp │ ├── 582A. GCD Table.cpp │ ├── 592D. Super M.cpp │ ├── 593B. Anton and Lines.cpp │ ├── 600E. Lomsat gelral.cpp │ ├── 603B. Moodular Arithmetic.cpp │ ├── 603C. Lieges of Legendre .cpp │ ├── 607A. Chain Reaction.cpp │ ├── 611C. New Year and Domino.cpp │ ├── 615D. Multipliers.cpp │ ├── 616D. Longest k-Good Segment.cpp │ ├── 622C. Not Equal on a Segment.cpp │ ├── 626D. Jerry's Protest.cpp │ ├── 630H. Benches.cpp │ ├── 631E. Product Sum.cpp │ ├── 632E. Thief in a Shop.cpp │ ├── 637D. Running with Obstacles.cpp │ ├── 645D. Robot Rapping Results Report.cpp │ ├── 650A. Watchmen.cpp │ ├── 652D. Nested Segments.cpp │ ├── 660F. Bear and Bowling 4.cpp │ ├── 670E. Correct Bracket Sequence Editor.cpp │ ├── 675D. Tree Construction.cpp │ ├── 677D. Vanya and Treasure.cpp │ ├── 682D. Alyona and Strings.cpp │ ├── 710F. String Set Queries.cpp │ ├── 718C. Sasha and Array.cpp │ ├── 71A. Way Too Long Words.py │ ├── 722D. Generating Sets.cpp │ ├── 729E. Subordinates.cpp │ ├── 731C. Socks.cpp │ ├── 735A. Ostap and Grasshopper.cpp │ ├── 735B. Urbanization.cpp │ ├── 735C. Tennis Championship.cpp │ ├── 738.cpp │ ├── 738A. Interview with Oleg.cpp │ ├── 738C. Road to Cinema.cpp │ ├── 742B. Arpa’s obvious problem and Mehrdad’s terrible solution.cpp │ ├── 758D. Ability To Convert.cpp │ ├── 75C. Modified GCD.cpp │ ├── 763B. Timofey and rectangles.cpp │ ├── 766E. Mahmoud and a xor trip.cpp │ ├── 768C. Jon Snow and his Favourite Number.cpp │ ├── 770C. Online Courses In BSU.cpp │ ├── 776D. The Door Problem.cpp │ ├── 77B. Falling Anvils.cpp │ ├── 786B. Legacy.cpp │ ├── 78C. Beaver Game.cpp │ ├── 792D. Paths in a Complete Binary Tree.cpp │ ├── 796C. Bank Hacking.cpp │ ├── 796D. Police Stations.cpp │ ├── 797C. Minimal string.cpp │ ├── 79C. Beaver.cpp │ ├── 802H. Fake News (medium).cpp │ ├── 802I. Fake News (hard).cpp │ ├── 808D. Array Division.cpp │ ├── 811C. Vladik and Memorable Trip.cpp │ ├── 813C. The Tag Game.cpp │ ├── 815A. Karen and Game.cpp │ ├── 817E. Choosing The Commander.cpp │ ├── 839C. Journey.cpp │ ├── 847E. Packmen.cpp │ ├── 858D. Polycarp's phone book.cpp │ ├── 859C. Pie Rules.cpp │ ├── 864D. Make a Permutation!.cpp │ ├── 86D. Powerful array.cpp │ ├── 873D. Merge Sort.cpp │ ├── 873E brute.cpp │ ├── 873E. Awards For Contestants.cpp │ ├── 873e random.cpp │ ├── 876E. National Property.cpp │ ├── 877E. Danil and a Part-time Job.cpp │ ├── 888D. Almost Identity Permutations.cpp │ ├── 888E. Maximum Subsequence.cpp │ ├── 899 again.cpp │ ├── 899F. Letters Removing.cpp │ ├── 899F.cpp │ ├── 914D - Bash and a Tough Math Puzzle.cpp │ ├── 917A. The Monster.cpp │ ├── 91A. Newspaper Headline.cpp │ ├── 91E. Igloo Skyscraper.cpp │ ├── 920F. SUM and REPLACE.cpp │ ├── 922D. Robot Vacuum Cleaner.cpp │ ├── 946D. Timetable.cpp │ ├── 946E. Largest Beautiful Number.cpp │ ├── 965D. Single-use Stones.cpp │ ├── 96A.cpp │ ├── 982D. Shark.cpp │ ├── 985F. Isomorphic Strings.cpp │ ├── A. The Closest Pair.cpp │ ├── D. The Maths Lecture.cpp │ ├── asdsad.cpp │ ├── deb.cpp │ ├── map.cpp │ ├── table.cpp │ └── test.cpp └── iii.md ├── HDU ├── 2993 MAX Average Problem NEW.cpp ├── 2993 MAX Average Problem.cpp ├── 2993 brute.cpp ├── 2993 vector.cpp ├── 3436 Queue-jumpers.cpp ├── Play with Chain.cpp └── Robotic Sort.cpp ├── LightOJ ├── 1000.c ├── 1001.c ├── 1002 - Country Roads.cpp ├── 1003 - Drunk.cpp ├── 1004 - Monkey Banana Problem.c ├── 1005- rooks.cpp ├── 1006 - Hex-a-bonacci.cpp ├── 1007 - Mathematically Hard.cpp ├── 1008 - Fibsieve`s Fantabulous Birthday.c ├── 1009 - Back to Underworld.cpp ├── 1010 - Knights in Chessboard.c ├── 1010 - Marriage Ceremonies.c ├── 1011 - Marriage Ceremonies (backTrack, TLE).cpp ├── 1011 - Marriage Ceremonies.c ├── 1011 - Marriage Ceremonies.cpp ├── 1012 - Guilty Prince.c ├── 1013 - Love Calculator.cpp ├── 1014 - Ifter Party.c ├── 1015 - Brush (I).c ├── 1016 - Brush (II).cpp ├── 1017 - Brush (III).c ├── 1017 - Brush (III).cpp ├── 1018 - Brush (IV) 2.cpp ├── 1018 - Brush (IV).cpp ├── 1019 - Brush (V).cpp ├── 1020 - A Childhood Game.c ├── 1021 - Painful Bases 2.cpp ├── 1021 - Painful Bases.cpp ├── 1022 - Circle in Square.c ├── 1023 - Discovering Permutations.c ├── 1023 - Discovering Permutations.cpp ├── 1024 - Eid.cpp ├── 1025 - The Specials Menu.cpp ├── 1025 - The special menu faster.cpp ├── 1025 net.cpp ├── 1026 - Critical Links.cpp ├── 1027.c ├── 1028 - Trailing Zeroes (I).cpp ├── 1029 - Civil and Evil Engineer kruskal.cpp ├── 1030 - Discovering Gold 2 .cpp ├── 1030 - Discovering Gold.cpp ├── 1031 - Easy Game 2.cpp ├── 1031 - Easy Game.c ├── 1031 - Easy Game.cpp ├── 1032 - Fast Bit Calculations new.cpp ├── 1032 - Fast Bit Calculations.cpp ├── 1033 - Generating Palindromes.cpp ├── 1034 - Hit the Light Switches.cpp ├── 1035 - Intelligent Factorial Factorization.cpp ├── 1036 - A Refining Company.cpp ├── 1037 - Agent 47.cpp ├── 1038 - Race to 1 Again.cpp ├── 1039 - A Toy Company.cpp ├── 1040 - Donation.cpp ├── 1041 - Road Construction.cpp ├── 1042 - Secret Origins.c ├── 1043 - Triangle Partitioning.cpp ├── 1044 - Palindrome Partitioning.cpp ├── 1045 - Digits of Factorial.c ├── 1046 - Rider.cpp ├── 1047 - Neighbor House.cpp ├── 1048 - Conquering Keokradong .cpp ├── 1049 - One Way Roads.cpp ├── 1050 - Marbles.cpp ├── 1051 - Good or Bad.cpp ├── 1052 - String Growth.cpp ├── 1053 - Higher Math.c ├── 1054 - Efficient Pseudo Code.cpp ├── 1055 - Going Together 2.cpp ├── 1055 - Going Together.cpp ├── 1056 - Olympics.cpp ├── 1057 - Collecting Gold 2.cpp ├── 1057 - Collecting Gold 3.cpp ├── 1057 - Collecting Gold.cpp ├── 1058 - Parallelogram Counting.cpp ├── 1059 - Air Ports.cpp ├── 1060 - nth Permutation.cpp ├── 1061 - N Queen Again.cpp ├── 1063 - Ant Hills.cpp ├── 1064 - Throwing Dice.cpp ├── 1065 - Number Sequence.cpp ├── 1066 - Gathering Food.cpp ├── 1067 - Combinations.cpp ├── 1068 - Investigation.cpp ├── 1069 - Lift.c ├── 1070 - Algebraic Problem.cpp ├── 1071 - Baker Vai.cpp ├── 1072 - Calm Down.cpp ├── 1073 - DNA Sequence.cpp ├── 1074 - Extended Traffic.cpp ├── 1075 - Finding Routes.cpp ├── 1076 - Get the Containers 2.cpp ├── 1076 - Get the Containers.cpp ├── 1077 - How Many Points .cpp ├── 1078 - Integer Divisibility.cpp ├── 1079 - Just another Robbery ITERATIVE.cpp ├── 1080 - Binary Simulation.cpp ├── 1081 - Square Queries.cpp ├── 1082 - Array Queries.cpp ├── 1083 - Histogram GREEDY.cpp ├── 1083 - Histogram.cpp ├── 1084 - Winter NEW.cpp ├── 1085 - All Possible Increasing Subsequences.cpp ├── 1086 - Jogging Trails.cpp ├── 1087 - Diablo new.cpp ├── 1089 - Points in Segments (II).cpp ├── 1090 - Trailing Zeroes (II).cpp ├── 1091 - The Fastest Sorting Ever!.cpp ├── 1092 - Lighted Panels.cpp ├── 1093 - Ghajini.cpp ├── 1094 - Farthest Nodes in a Tree.cpp ├── 1095 - Arrange the Numbers 2.cpp ├── 1095 - Arrange the Numbers.cpp ├── 1096 - nth Term.cpp ├── 1097 - Lucky Number.cpp ├── 1098 - A New Function.cpp ├── 1099 - Not the Best.cpp ├── 1100 - Again Array Queries.cpp ├── 1101 - A Secret Mission.cpp ├── 1102 - Problem Makes Problem.cpp ├── 1103 - Castle Walls.cpp ├── 1104 - Birthday Paradox.cpp ├── 1105 - Fi Binary Number.cpp ├── 1106 - Gone Fishing.cpp ├── 1107 - How Cow.c ├── 1108 - Instant View of Big Bang.cpp ├── 1109 - False Ordering.c ├── 1109 - False Ordering.cpp ├── 1110 - An Easy LCS 2.cpp ├── 1110 - An Easy LCS.cpp ├── 1111 - Best Picnic Ever.cpp ├── 1112 - Curious Robin Hood BIT .cpp ├── 1112 - Curious Robin Hood SEGMENT TREE .cpp ├── 1113 - Discover the Web.c ├── 1113 - Discover the Web.cpp ├── 1114 - Easily Readable MAP.cpp ├── 1115 - Filling the Regions.cpp ├── 1116 - Ekka Dokka.c ├── 1117 helping cicada.c ├── 1118 - Incredible Molecules NEW.cpp ├── 1118 - Incredible Molecules.cpp ├── 1119 - Pimp My Ride.cpp ├── 1120 - Rectangle Union ORS.cpp ├── 1122 - Digit Count.cpp ├── 1123 - Trail Maintenance.cpp ├── 1124 - Cricket Ranking.cpp ├── 1124 cricket ranking.c ├── 1125 - Divisible Group Sums.cpp ├── 1126 - Building Twin Towers.cpp ├── 1127 - Funny Knapsack.cpp ├── 1128 - Greatest Parent.cpp ├── 1129 - Consistency Checker.cpp ├── 1131 - Just Two Functions.cpp ├── 1132 - Summing up Powers.cpp ├── 1133 - Array Simulation.cpp ├── 1134 - Be Efficient.cpp ├── 1135 - Count the Multiples of 3 new.cpp ├── 1135 - Count the Multiples of 3.cpp ├── 1136 - Division by 3.c ├── 1137 - Expanding Rods.cpp ├── 1138 - Trailing Zeroes (III).cpp ├── 1139 - 8 Puzzle.cpp ├── 1140 - How Many Zeroes 2 .cpp ├── 1140 - How Many Zeroes.cpp ├── 1141 - Number Transformation.cpp ├── 1142 - Summing up Powers (II).cpp ├── 1144 - Ray Gun PIE.cpp ├── 1144 ray gun efficient.cpp ├── 1144 ray gun.c ├── 1145 - Dice (I).cpp ├── 1146 - Closest Distance.cpp ├── 1147 - Tug of War BITMASK.cpp ├── 1148 - Mad Counting.cpp ├── 1149 - Factors and Multiples FLOW.cpp ├── 1150 - Ghosts! BPM NEW.cpp ├── 1150 - Ghosts! BPM.cpp ├── 1150 - Ghosts!.cpp ├── 1151 - Snakes and Ladders.cpp ├── 1152 - Hiding Gold.cpp ├── 1153 - Internet Bandwidth.cpp ├── 1154 - Penguins DINIC.cpp ├── 1155 - Power Transmission.cpp ├── 1156 - Jumping Frogs DINIC.cpp ├── 1157 - LCS Revisited.cpp ├── 1158 - Anagram Division.cpp ├── 1159 - Batman.cpp ├── 1160 - Discovering Paths in Grid.cpp ├── 1161 - Extreme GCD.cpp ├── 1162 - Min Max Roads.cpp ├── 1163 - Bank Robbery.cpp ├── 1164 - Horrible Queries.cpp ├── 1165 - Digit Dancing.cpp ├── 1165 net.cpp ├── 1166 - Old Sorting.cpp ├── 1167 - Dangerous Tunnels.cpp ├── 1168 - Wishing Snake.cpp ├── 1169 - Monkeys on Twin Tower.cpp ├── 1170 - Counting Perfect BST.cpp ├── 1171 - Knights in Chessboard (II) HOPCROFT.cpp ├── 1173 - The Vindictive Coach.cpp ├── 1174 - Commandos.cpp ├── 1175 - Jane and the Frost Giants.cpp ├── 1176 - Getting a T-shirt.cpp ├── 1177 - Angry Programmer BFS.cpp ├── 1177 - Angry Programmer PFS.cpp ├── 1178 - Trapezium.cpp ├── 1179 - Josephus Problem.cpp ├── 1180 - Software Company ITERATIVE.cpp ├── 1180 n5.cpp ├── 1181 - Odd Looking Average.cpp ├── 1182 - Parity.c ├── 1183 - Computing Fast Average.cpp ├── 1184 - Marriage Media.cpp ├── 1184 net.cpp ├── 1185 - Escape.cpp ├── 1186 - Incredible Chess.cpp ├── 1187 - Lining up Students SEGTREE.cpp ├── 1188 - Fast Queries.cpp ├── 1189 - Sum of Factorials.c ├── 1190 - Sleepwalking BS.cpp ├── 1190 - Sleepwalking.cpp ├── 1191 - Bar Codes.cpp ├── 1192 - Left Right.cpp ├── 1193 - Dice (II).cpp ├── 1194 - Colored T-Shirts.cpp ├── 1195 - Similar Trees.cpp ├── 1197 - Help Hanzo.cpp ├── 1198 - Karate Competition 2.cpp ├── 1198 - Karate Competition.cpp ├── 1199 - Partitioning Game.cpp ├── 1200 - Thief.cpp ├── 1201 - A Perfect Murder.cpp ├── 1202 - Bishops.c ├── 1203 - Guarding Bananas.cpp ├── 1204 NEW.cpp ├── 1205 - Palindromic Numbers NEW NEW.cpp ├── 1205 - Palindromic Numbers NEW.cpp ├── 1205 - Palindromic Numbers.cpp ├── 1206 - Scheduling Taxi Cabs.cpp ├── 1207 - Posters for Election.cpp ├── 1209 - Strange Voting BPM.cpp ├── 1210 - Efficient Traffic System.cpp ├── 1211 - Intersection of Cubes.cpp ├── 1212 - Double Ended Queue.cpp ├── 1213 - Fantasy of a Summation.cpp ├── 1214 - Large Division.cpp ├── 1215 - Finding LCM.cpp ├── 1216 - Juice in the Glass.cpp ├── 1217 - Neighbor House (II).cpp ├── 1218-Multiple-Free-Subset.cpp ├── 1220 - Mysterious Bacteria.cpp ├── 1222 - Gift Packing MIN COST MAX FLOW.cpp ├── 1223 - Testing Mailboxes.cpp ├── 1224 - DNA Prefix.cpp ├── 1225 - Palindromic Numbers (II).cpp ├── 1226 - One Unit Machine.cpp ├── 1227 - Boiled Eggs.cpp ├── 1229 - Treblecross.cpp ├── 1230 - Placing Lampposts.cpp ├── 1231 - Coin Change (I).cpp ├── 1232 - Coin Change (II).cpp ├── 1233 - Coin Change (III).cpp ├── 1234 - Harmonic Number.cpp ├── 1235 - Coin Change (IV).cpp ├── 1236 - Pairs Forming LCM.cpp ├── 1237 - Cyber Cafe.cpp ├── 1238 - Power Puff Girls.cpp ├── 1239 - Convex Fence.cpp ├── 1240 - Point Segment Distance (3D) TERNARY.cpp ├── 1241 - Pinocchio.cpp ├── 1244 - Tiles.cpp ├── 1246 - Colorful Board EFF.cpp ├── 1246 - Colorful Board.cpp ├── 1247 - Matrix Game.cpp ├── 1248 - Dice (III).cpp ├── 1249 - Chocolate Thief.cpp ├── 1251 - Forming the Council.cpp ├── 1252 - Maintaining Communities.cpp ├── 1253 - Misere Nim.cpp ├── 1254 - Prison Break NEW.cpp ├── 1254 - Prison Break.cpp ├── 1254 net.cpp ├── 1255 - Substring Frequency.cpp ├── 1257 - Farthest Nodes in a Tree (II) 2.cpp ├── 1257 - Farthest Nodes in a Tree (II).cpp ├── 1258 - Making Huge Palindromes.cpp ├── 1259 - Goldbach`s Conjecture.cpp ├── 1261 - K-SAT Problem.cpp ├── 1262 - Diagonal Sum.cpp ├── 1262 rand.cpp ├── 1263 - Equalizing Money.cpp ├── 1265 - Island of Survival 2.cpp ├── 1265 - Island of Survival.cpp ├── 1266 - Points in Rectangle BIT.cpp ├── 1267 - Points in Rectangle (II).cpp ├── 1268 - Unlucky Strings.cpp ├── 1269 - Consecutive Sum.cpp ├── 1270 - Tiles (II).cpp ├── 1271 - Better Tour.cpp ├── 1272 - Maximum Subset Sum.cpp ├── 1272 brute.cpp ├── 1273 - Strange Island.cpp ├── 1274 - Beating the Dataset.cpp ├── 1275 - Internet Service Providers.cpp ├── 1276 - Very Lucky Numbers.cpp ├── 1277 - Looking for a Subsequence.cpp ├── 1279 - Graph Coloring.cpp ├── 1281 - New Traffic System.cpp ├── 1282 - Leading and Trailing.cpp ├── 1283 - Shelving Books.cpp ├── 1283 net.cpp ├── 1284 - Lights inside 3D Grid.cpp ├── 1285 - Drawing Simple Polygon.cpp ├── 1287 - Where to Run.cpp ├── 1288 - Subsets Forming Perfect Squares.cpp ├── 1289 - LCM from 1 to n NEW .cpp ├── 1289 - LCM from 1 to n.cpp ├── 1291 - Real Life Traffic new.cpp ├── 1291 - Real Life Traffic.cpp ├── 1292 - Laser Shot.cpp ├── 1292net.cpp ├── 1294 - Positive Negative Sign.cpp ├── 1295 - Lighting System Design.cpp ├── 1296 - Again Stone Game.cpp ├── 1297 - Largest Box.cpp ├── 1298 - One Theorem, One Year.cpp ├── 1300 - Odd Personality.cpp ├── 1300 random.cpp ├── 1301 - Monitoring Processes.cpp ├── 1303 - Ferris Wheel CHEAT.cpp ├── 1303 - Ferris Wheel.cpp ├── 1304 - The Best Contest Site Ever.cpp ├── 1304 rand.cpp ├── 1305 - Area of a Parallelogram.cpp ├── 1306 - Solutions to an Equation.cpp ├── 1307 - Counting Triangles.cpp ├── 1308 - Ant Network.cpp ├── 1310 - Tiles (III).cpp ├── 1311 - Unlucky Bird.cpp ├── 1314 - Names for Babies.cpp ├── 1315 - Game of Hyper Knights.cpp ├── 1316 - A Wedding Party.cpp ├── 1317 - Throwing Balls into the Baskets.cpp ├── 1319 - Monkey Tradition.cpp ├── 1321 - Sending Packets.cpp ├── 1322 - Worst Case Trie.cpp ├── 1325 - Distributing Chocolates.cpp ├── 1326 - Race 2.cpp ├── 1326 - Race.cpp ├── 1327 - Help the Winners.cpp ├── 1327 random.cpp ├── 1328 - A Gift from the Setter.cpp ├── 1330 - Binary Matrix ADMOND CARP TLE.cpp ├── 1330 - Binary Matrix DINIC.cpp ├── 1331 - Agent J.cpp ├── 1332 - Kings in Chessboard.cpp ├── 1333 - Grid Coloring.cpp ├── 1334 - Genes in DNA.cpp ├── 1336 - Sigma Function.cpp ├── 1337 - The Crystal Maze.cpp ├── 1338 - Hidden Secret!.cpp ├── 1339 - Strongest Community.cpp ├── 1340 - Story of Tomisu Ghost.cpp ├── 1341 - Aladdin and the Flying Carpet.cpp ├── 1344 - Aladdin and the Game of Bracelets.cpp ├── 1346 - Aladdin and the Rocky Mountains(Code of Sudip bhai).cpp ├── 1347 - Aladdin and the Magical Lamp.cpp ├── 1348 - Aladdin and the Return Journey NEW.cpp ├── 1348 - Aladdin and the Return Journey.cpp ├── 1349 - Aladdin and the Optimal Invitation.cpp ├── 1349.cpp ├── 1354 - IP Checking.cpp ├── 1355 - Game of CS.cpp ├── 1356 - Prime Independence.cpp ├── 1357 - Corrupted Friendship.CPP ├── 1359 - Sabotaging Contest.cpp ├── 1360 - Skyscraper.cpp ├── 1364 - Expected Cards 2.cpp ├── 1364 - Expected Cards.cpp ├── 1366 - Pair of Touching Circles.cpp ├── 1369 - Answering Queries.cpp ├── 1370 - Bi-shoe and Phi-shoe.cpp ├── 1371 - Energetic Pandas.cpp ├── 1374 - Confusion in the Problemset.cpp ├── 1377 - Blade and Sword.cpp ├── 1379 - Toll Management.cpp ├── 1382 - The Queue.cpp ├── 1383 - Underwater Snipers.cpp ├── 1385 - Kingdom Division.cpp ├── 1387 - Setu.cpp ├── 1389 - Scarecrow.cpp ├── 1390 - Weight Comparison.cpp ├── 1390 rand.cpp ├── 1393 - Crazy Calendar.cpp ├── 1395 - A Dangerous Maze (II).cpp ├── 1396 - Palindromic Numbers (III).cpp ├── 1397 - Sudoku Solver 2.cpp ├── 1397 - Sudoku Solver NEW.cpp ├── 1397 - Sudoku Solver.cpp ├── 1400 - Employment.cpp ├── 1401 - No More Tic-tac-toe.cpp ├── 1403 - Air Raid.cpp ├── 1404 - Sending Secret Messages.cpp ├── 1405 - The Great Escape.cpp ├── 1406 - Assassin`s Creed.cpp ├── 1406 - Assassins Creed.cpp ├── 1407 - Explosion.cpp ├── 1410 - Consistent Verdicts.cpp ├── 1411 - Rip Van Winkle's Code TLE.cpp ├── 1411 - Rip Van Winkle's Code.cpp ├── 1411rand.cpp ├── 1412 - Visiting Islands.cpp ├── 1414 - February 29.cpp ├── 1417 - Forwarding Emails.cpp ├── 1418 - Trees on My Island.cpp ├── 1420 - Subsequences forming Strings NEW.cpp ├── 1420 - Subsequences forming Strings WA.cpp ├── 1421 - Wavio Sequence.cpp ├── 1422 - Halloween Costumes.cpp ├── 1424 - New Land.cpp ├── 1425 - The Monkey and the Oiled Bamboo.cpp ├── 1427 - Substring Frequency (II).cpp ├── 1428 - Melody Comparison.cpp ├── 1429 - Assassin`s Creed (II).cpp ├── 1433 - Minimum Arc Distance.cpp └── 1434 - Patch Quilt.cpp ├── POJ ├── 16393 Space Elevator ITERATIVE.cpp ├── 16393 Space Elevator.cpp ├── 1704 Georgia and Bob.cpp ├── 1991 Turning in Homework.cpp ├── 2411 Mondriaan's Dream.cpp ├── 2663 Tri Tiling.cpp └── 3042 Grazing on the Run.cpp ├── README.md ├── SPOJ ├── ABA12C - Buying Apples! ITERATIVE.cpp ├── ABA12C - Buying Apples! REC.cpp ├── ABCDEF - ABCDEF.cpp ├── ACQUIRE - Land Acquisition.cpp ├── ADAFIELD - Ada and Field.cpp ├── AEROLITE - The Secret of an Aerolite REC.cpp ├── AGGRCOW - Aggressive cows.cpp ├── APIO10A - Commando.cpp ├── ARRAYSUB - subarrays.cpp ├── ASDASD.CPP ├── BALNUM - Balanced Numbers.cpp ├── BEADS - Glass Beads (Zahin).cpp ├── BEADS - Glass Beads.cpp ├── BGSHOOT - Shoot and kill (update in query).cpp ├── BGSHOOT line sweep init.cpp ├── BOMBER - Bomberman.cpp ├── BRCKTS - Brackets.cpp ├── BRKSTRNG - Breaking String.cpp ├── BUGLIFE - A Bug’s Life.cpp ├── COT - Count on a tree PERSISTANT.cpp ├── DISUBSTR - Distinct Substrings.cpp ├── DQUERY - D-query.cpp ├── FREQUENT - Frequent values.cpp ├── G - Sequence.cpp ├── GEOPROB - One Geometry Problem.cpp ├── GOT - Gao on a tree.cpp ├── GS - Going to school.cpp ├── GSS1 - Can you answer these queries I.cpp ├── GSS3 - Can you answer these queries III TREAP.cpp ├── GSS3 - Can you answer these queries III.cpp ├── GSS5 - Can you answer these queries V like 3.cpp ├── GSS5 - Can you answer these queries V.cpp ├── GSS6 - Can you answer these queries VI TREAP.cpp ├── GSS7 - Can you answer these queries VII.cpp ├── KGSS - Maximum Sum.cpp ├── KPMATRIX - Matrix.cpp ├── KQUERYO - K-Query Online.cpp ├── LCS - Longest Common Substring.cpp ├── LCS2 - Longest Common Substring II.cpp ├── LIM - Lost in Madrid.cpp ├── LIS2 - Another Longest Increasing Subsequence Problem PBDS.cpp ├── LIS2 - Another Longest Increasing Subsequence Problem.cpp ├── LOOPEXP - Loop Expectation.cpp ├── MAXMATCH - Maximum Self-Matching.cpp ├── MKTHNUM - K-th Number BS+DS.cpp ├── MKTHNUM - K-th Number PERSISTANT.cpp ├── MREPLBRC - Counting The Way of Bracket Replacement.cpp ├── MUL - Fast Multiplication.cpp ├── NICEDAY - The day of the competitors.cpp ├── NKLEAVES - Leaves NEW.cpp ├── NKLEAVES - Leaves.cpp ├── ORDERSET - Order statistic set TREAP.cpp ├── ORDERSET - Order statistic set.cpp ├── PALIN - The Next Palindrome.cpp ├── PATULJCI - Snow White and the N dwarfs (2).cpp ├── PATULJCI - Snow White and the N dwarfs.cpp ├── PERMUT1 - Permutations.cpp ├── POLYMUL - Polynomial Multiplication.cpp ├── POSTERS - Election Posters.cpp ├── PRIME1 - Prime Generator.cpp ├── PYRA - Treeramids.cpp ├── QTREE - Query on a tree.cpp ├── QTREE2 - Query on a tree II.cpp ├── QTREE3 - Query on a tree again!.cpp ├── QTREE4 - Query on a tree IV.cpp ├── QTREE5 - Query on a tree V.cpp ├── QWERTY04 - TRIVIADOR.cpp ├── RACETIME - Race Against Time SEGTREE PBDS.cpp ├── RACETIME - Race Against Time SQRT BIT c.cpp ├── RACETIME - Race Against Time SQRT BIT.cpp ├── RACETIME - Race Against Time.cpp ├── SUBLEX - Lexicographical Substring Search.cpp ├── TRICENTR - Triangle From Centroid.cpp ├── TSUM - Triple Sums.cpp ├── TTM - To the moon.cpp ├── VECTAR9 - Mangu Numbers.cpp ├── VFMUL - Very Fast Multiplication.cpp ├── WINDVANE - WIND VANE 2D SEGTREE.cpp ├── WPUZZLES - Word Puzzles AHO TLE.cpp ├── WPUZZLES - Word Puzzles AHO.cpp ├── apio net.cpp ├── bomber.cpp ├── brkts net.cpp ├── eular.cpp ├── gss5 net.cpp ├── loop.cpp ├── random.cpp ├── randomd.cpp ├── temp.cpp └── ttm net.cpp ├── Timus ├── 1017 - Staircase 2.cpp ├── 1017 - Staircase 3.cpp ├── 1017 - Staircase.cpp ├── 1042. Central Heating.cpp ├── 1152. False Mirrors.cpp ├── 1269. Obscene Words Filter.cpp ├── 1553. Caves and Tunnels.cpp └── 1989 - Subpalindromes.cpp ├── URAL ├── 1167. Bicolored Horses.cpp └── 1439. Battle with You-Know-Who.cpp ├── UVLive ├── 2738 - Postal Vans.cpp ├── 2738 bigint reduced.cpp ├── 2738 bigint.cpp ├── 2738 new.cpp ├── 6327 - Math Homework.cpp ├── 6808 - Best Position.cpp ├── 6900 - Road Repair.cpp ├── 8095 Rock Paper Scissors.cpp ├── case.cpp └── rand.cpp └── UVa ├── 0.c ├── 00101 - The Blocks Problem.cpp ├── 00102.c ├── 00108 - Maximum Sum.cpp ├── 00111.cpp ├── 00122 - Trees on the level.cpp ├── 00136.c ├── 00190.c ├── 00272.c ├── 00336 - A node too far.cpp ├── 00374 mun.c ├── 00374 muntasir.c ├── 00374.c ├── 00382.c ├── 00406 - Prime Cuts.cpp ├── 00408 - Uniform Generator.cpp ├── 00424 integer inquiry.c ├── 00429.cpp ├── 00458 new.c ├── 00458-the decoder (rank-380).c ├── 00459 - Graph Connectivity.cpp ├── 00488 net.c ├── 00488 raida.c ├── 00488 saadmaan sakib.c ├── 00488- Triangle wave (rank 70).c ├── 00492-pig latin (net helped algo).c ├── 00494.c ├── 00495.c ├── 00514 - Rails.cpp ├── 00523 - Minimum Transport Cost.cpp ├── 00530.c ├── 00544 - Heavy Cargo.cpp ├── 00558.cpp ├── 00573.c ├── 00579.c ├── 00591.c ├── 00616 coconuts.c ├── 00673 - Parentheses Balance.cpp ├── 00674 - coin change.cpp ├── 00679 - Dropping Balls.cpp ├── 00694.c ├── 00696 knight.c ├── 00719 - Glass Beads.cpp ├── 00821 - Page Hopping.cpp ├── 00834.c ├── 00897 - Anagrammatic Primes.cpp ├── 00897 random.cpp ├── 00908.cpp ├── 00990.cpp ├── 01124.c ├── 01599 - Ideal Path.cpp ├── 01625 - Color Length.cpp ├── 01644 without extra function (no use, with function better).c ├── 100 - Copy.c ├── 100 riddho.c ├── 100 shahin.c ├── 100.c ├── 10003 - Cutting Sticks.cpp ├── 10004 - Bicoloring.cpp ├── 10013 net.c ├── 10013 new.c ├── 10013 rai.c ├── 10013.c ├── 1002 - Country Roads.cpp ├── 10020 - Minimal coverage.cpp ├── 10035.c ├── 10038.c ├── 1004 bicoloring.c ├── 10041.c ├── 10055 amor.c ├── 10055.c ├── 10066 - The Twin Towers.cpp ├── 10070.c ├── 10079.c ├── 10086 - Test the Rods.cpp ├── 10101 net anuran.c ├── 10101 net.c ├── 10101 riddho.c ├── 10101- (helped by riddho).c ├── 10101.c ├── 1011 - Marriage Ceremonies.cpp ├── 10110.c ├── 10111 - Find the Winning Move.cpp ├── 10129 - Play on Words.cpp ├── 10130 - supersale.cpp ├── 10131 - Is Bigger Smarter.cpp ├── 10141 - Request for Proposal.c ├── 10161.c ├── 10165 - Stone Game.cpp ├── 1018.c ├── 10189 - Minesweeper.c ├── 102.c ├── 10209.c ├── 10212.c ├── 10229 - Modular Fibonacci.cpp ├── 10234 - Frequent Substrings.cpp ├── 10235-is emirp.c ├── 10267 - Graphical Editor.cpp ├── 10284 - Chessboard in FEN.cpp ├── 10288 - Coupons.cpp ├── 10302.c ├── 10305.cpp ├── 10305net.cpp ├── 10323.c ├── 10340.c ├── 10346 akash.c ├── 10346.c ├── 10347 raida.c ├── 10347.c ├── 10368 - Euclid's Game.cpp ├── 10369 - Arctic Network 2.cpp ├── 10369.cpp ├── 10375 - Choose and divide.cpp ├── 10432.c ├── 10469.c ├── 10473.c ├── 10490.c ├── 10491 - Cows and Cars.cpp ├── 10522.c ├── 10523.c ├── 10533.c ├── 10591 - Happy Number.cpp ├── 10611 - The Playboy Chimp.cpp ├── 1063 - Ant Hills.cpp10107 - What is the Median.cpp ├── 10633.c ├── 10653.cpp ├── 10679 - I Love Strings!!.cpp ├── 10684 net.c ├── 10684- [learn kadane's algo].c ├── 10685 - nature.cpp ├── 10696 f91.c ├── 10699.c ├── 10771.c ├── 10773.c ├── 10783.c ├── 10784.c ├── 10791 - Minimum Sum LCM.cpp ├── 10806 - Dijkstra, Dijkstra..cpp ├── 10812.c ├── 10820 - Send a Table.cpp ├── 10870 - Recurrences.cpp ├── 10879.c ├── 10891 - Game of Sum.cpp ├── 10900 - So you want to be a 2n-aire.cpp ├── 10927 - Bright Lights.cpp ├── 10931.c ├── 10934 - Dropping water balloons REC.cpp ├── 10970.c ├── 11000.c ├── 11015 - 05-2 Rendezvous.cpp ├── 11044.c ├── 11045 - My T-shirt suits me.cpp ├── 11057.c ├── 11060.cpp ├── 11080.CPP ├── 11100.c ├── 11137.cpp ├── 11152.c ├── 11172.c ├── 11181 - Probability Given.cpp ├── 11181 new.cpp ├── 11185.c ├── 11192 new.c ├── 11192.c ├── 11219 shuvo.c ├── 11219.c ├── 11231.c ├── 11235 random.cpp ├── 11254.c ├── 11297 - Census.cpp ├── 113.c ├── 11311 - Exclusively Edible.cpp ├── 11321.cpp ├── 11331 - the joys of farming.cpp ├── 11332 - Summing Digits.cpp ├── 11344 net.c ├── 11344 raida.c ├── 11344 shahin.c ├── 11344.c ├── 11345.c ├── 11362 - Phone List.cpp ├── 11388 new.c ├── 11388!!!.c ├── 11428.c ├── 11450 - Wedding shopping.cpp ├── 11461.c ├── 11462 shahin.c ├── 11462.c ├── 11464 - Even Parity.cpp ├── 11468 - Substring.cpp ├── 11479.c ├── 11489 - Integer Game.cpp ├── 11489 net.cpp ├── 11498.c ├── 11503 - Virtual Friends.cpp ├── 11503 - virtual network.cpp ├── 11504 - dominoes.cpp ├── 11504 2.cpp ├── 11504 net .cpp ├── 11512 - GATTACA.cpp ├── 11512 random.cpp ├── 11517 - Exact Change .cpp ├── 11530.c ├── 11542 - Square.cpp ├── 11547.c ├── 11577.c ├── 11582 - Colossal Fibonacci Numbers!.cpp ├── 11614.c ├── 11677.c ├── 11723.c ├── 11727.c ├── 11764- mario.c ├── 11777.c ├── 11799.c ├── 11805 sakib.c ├── 11805.c ├── 11849.c ├── 11853 - Paintball.cpp ├── 11875 sakib.c ├── 11875.c ├── 11877 riddho.c ├── 11877.c ├── 11879 raida.c ├── 11879.c ├── 11879raida2.c ├── 11900 net.c ├── 11900.c ├── 11909.c ├── 11934.c ├── 11942.c ├── 11984.c ├── 12032 - The Monkey and the Oiled Bamboo.c ├── 12039 - Goldbach's Cardinality.cpp ├── 1204 - Fun Game.cpp ├── 12099 - The Bookcase.cpp ├── 12099 new.cpp ├── 12105 - Bigger is Better.cpp ├── 12114 - Bachelor Arithmetic.cpp ├── 12115 - Nested Squares.cpp ├── 12118 - Inspector's Dilemma.cpp ├── 12134 - Find the Format String.cpp ├── 12135 - Switch Bulbs.cpp ├── 12136 - Schedule of a Married Man.cpp ├── 12137 - Puzzles of Triangles.cpp ├── 12139 - Clicking Checkboxes.cpp ├── 12140 - Magic Rings DP+GEO.cpp ├── 12140 - Magic Rings INCOMPLETE.cpp ├── 12143 - Stopping Doom's Day.cpp ├── 12149.c ├── 12169 - Disgruntled Judge.cpp ├── 12171 - Sculpture.cpp ├── 12191 - File Recover.cpp ├── 12191 rand.cpp ├── 1220 - Party at Hali-Bula.cpp ├── 12206 - Stammering Aliens.cpp ├── 12207 - That is Your Queue.cpp ├── 12208 - How Many Ones Needed.cpp ├── 12209 - Foot Notes.cpp ├── 12210 - A Match Making Problem.c ├── 12216 - How Many bases.cpp ├── 12244 - Growing Strings AC WA.cpp ├── 12244 Growing String AC+TREE.cpp ├── 12257 - The Queue.cpp ├── 12279 - Emoogle Balance.cpp ├── 12280 - A Digital Satire of Digital Age.cpp ├── 12282 - OmniGravity.cpp ├── 12284 - Digital Matrix.cpp ├── 12285 - Knockout Tournaments.cpp ├── 12286 - Optimal Store.cpp ├── 12289.c ├── 1230.c ├── 12372.c ├── 12376.cpp ├── 12403.c ├── 12405 - Scarecrow.c ├── 12442.cpp ├── 12461 - Airplane.cpp ├── 12468.c ├── 12473 - Common Palindrome.cpp ├── 12474 - Draw and Score.cpp ├── 12475 - Elliptic Athletics Track.cpp ├── 12477 - Good Measures of Dispersion.cpp ├── 12478.c ├── 1249 - Euclid.cpp ├── 12497 - Chatgaiya Postman Problem.cpp ├── 12499 - I am Dumb 3.cpp ├── 12502.c ├── 12517 new.c ├── 12517 new2.c ├── 12517.c ├── 1252 - Twenty Questions.cpp ├── 12524 - Arranging Heaps.cpp ├── 12543 - Longest Word.c ├── 12578.c ├── 12585 - Poker End Games.cpp ├── 12611 - Beautiful Flag.cpp ├── 12611.c ├── 12612 - Cube Killer.cpp ├── 12613 Distinct Substring 2.cpp ├── 12614 - Earn For Future.cpp ├── 12619 - Just Make A Wish.cpp ├── 1262 - Password.cpp ├── 12700 riddho.c ├── 12700!.c ├── 12715 - Watching the Kangaroo.cpp ├── 12715 alada.cpp ├── 12716 - GCD XOR.cpp ├── 12716 brute.cpp ├── 12879 - Golf Bot.cpp ├── 12897 - Decoding Baby Boos.cpp ├── 12898 - And Or.cpp ├── 12900 - Flood in Gridland.cpp ├── 12901 - Refraction.cpp ├── 12903 - Just Some Permutations.cpp ├── 13148 - A Giveaway.cpp ├── 13149 - Game of XOR.cpp ├── 13149 rand.cpp ├── 13150 - National Bomb Defusing Squad.cpp ├── 13151 - Rational Grading.cpp ├── 13152 - Balanced String.cpp ├── 13153 - Number of Connected Components.cpp ├── 13154 - Extreme XOR Sum.cpp ├── 13157 - Prime Distance.cpp ├── 13272 - Bracket Sequence.cpp ├── 13273 - Making a Team.cpp ├── 13274 - Christmas Tree.cpp ├── 13275 - Leap Birthdays.cpp ├── 13276 - Megamind.cpp ├── 13277 - XOR Path.cpp ├── 13278 - Angry Birds Transformers.cpp ├── 13279 - Divisors.cpp ├── 13280 - Substring Sorting.cpp ├── 1331 - Minimax Triangulation NEW.cpp ├── 1331 - Minimax Triangulation.cpp ├── 1331 net.cpp ├── 1331 rand.cpp ├── 1336 - Fixing the Great Wall.cpp ├── 1336 WA.cpp ├── 1336 rand.cpp ├── 1412 - Fund Management.cpp ├── 151.c ├── 1585.c ├── 1626 - Brackets sequence.cpp ├── 1628 - Pizza Delivery.cpp ├── 1628 chinese.cpp ├── 1635 - Irrelevant Elements.cpp ├── 1636 - Headshot.cpp ├── 1638 - Pole Arrangement.cpp ├── 1639 - Candy.cpp ├── 1639 net.cpp ├── 1644 prime gap (rank 51).c ├── 1648 - Business Center.cpp ├── 1726 - Automatic Cheater Detection.cpp ├── 1727 - Counting Weekend Days.cpp ├── 1729 - Owllen.cpp ├── 1730 - Sum of MSLCM.cpp ├── 1734 - Numbered Cards.cpp ├── 191.c ├── 272- tex quotes.c ├── 299.c ├── 350 - Pseudo-Random Numbers.cpp ├── 369.c ├── 378 rizvee.c ├── 378.c ├── 382 noboni.c ├── 382 test.c ├── 400483.c ├── 401 - Palindromes.cpp ├── 439 - knight moves.cpp ├── 439 net.cpp ├── 492 net.c ├── 524 - Prime Ring Problem.cpp ├── 530.c ├── 543.c ├── 580 - Critical Mass.cpp ├── 686.c ├── 688 - Mobile Phone Coverage.cpp ├── 719 - Glass Beads.cpp ├── 7273 - Black Vienna.cpp ├── 8077 - Brick Walls.cpp ├── 834 nabil.c ├── 836.c ├── 847 - A Multiplication Game.cpp └── 990 - Diving for Gold.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/Articulation, Bridge, BCC.cpp: -------------------------------------------------------------------------------- 1 | int tim = 0; 2 | void dfs(int u, int par = -1) { 3 | low[u] = dis[u] = ++tim; 4 | int v, sz = g[u].size(), comp = 0; 5 | 6 | for(int i = 0; i < sz; ++i) { 7 | v = g[u][i]; 8 | if(v == par) continue; 9 | else if(dis[v]) low[u] = min(low[u], disc[v]); 10 | else { 11 | ++comp; 12 | dfs(v, u); 13 | 14 | if(par == -1 && comp > 1) arti[u] = true; 15 | if(par != -1 && low[v] >= dis[u]) arti[u] = true; 16 | 17 | low[u] = min(low[u], low[v]); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/BS in descending array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define vi vector 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vi v = {10, 9, 6, 4, 2, 1, 0, -2, -3}; 8 | int x = 6; 9 | int r = lower_bound(v.begin(), v.end(), x, greater()) - v.begin(); 10 | int s = upper_bound(v.begin(), v.end(), x, greater()) - v.begin(); 11 | 12 | cout << r << ' ' << s << endl; 13 | } 14 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/Extended Euclid.cpp: -------------------------------------------------------------------------------- 1 | /// EXTENDED EUCLID ON Ax + By = C 2 | /// OTHER SOLUTIONS : ( x - r*B/g , y + r*A/g ) where g = gcd(A,B) , (x,y) is the general solution from egcd , r is any integer 3 | /// A LOT OF SPECIAL CASES OCCURS 4 | 5 | struct euclid { 6 | int g, x,y; 7 | euclid() {} 8 | euclid(int gg, int xx, int yy) { 9 | g = gg; x = xx; y = yy; 10 | } 11 | }; 12 | euclid egcd(int a, int b) { 13 | if(b == 0) return euclid(a, 1, 0); 14 | euclid temp = egcd(b, a%b); 15 | return euclid(temp.g, temp.y, temp.x - temp.y*(a/b)); 16 | } 17 | int main() { 18 | euclid ans = egcd(-10, -8); 19 | cout << ans.g << ' ' << ans.x << ' ' << ans.y << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/LOJ/1282 - Leading and Trailing.cpp: -------------------------------------------------------------------------------- 1 | ll bigMod(ll n, ll r) { 2 | if(!n) return 0; 3 | if(!r) return 1; 4 | if(r%2) return (bigMod(n, r-1)*n) % 1000; 5 | ll ans = bigMod(n, r/2); 6 | return (ans*ans) % 1000; 7 | } 8 | 9 | int main() { 10 | 11 | int T; 12 | scanf("%d", &T); 13 | for(int t=1; t<=T; t++) { 14 | int n,k; 15 | scanf("%d %d", &n,&k); 16 | 17 | long double dn = n; n = n % 1000; 18 | int tail = 1; 19 | long double c = k * log10(dn); 20 | c = c - floor(c); 21 | int head = (int)pow((long double)10.0, 2 + c); 22 | 23 | // int a = floor(bigMod1(n, k)); 24 | printf("Case %d: %d %03lld\n",t, head, bigMod(n,k)); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/Sliding Window RMQ.cpp: -------------------------------------------------------------------------------- 1 | int n,k, ara[LIM+10]; 2 | 3 | int main() { 4 | scanf("%d", &n); 5 | for(int i=0; idq; 9 | 10 | for(int i=0; i k-1) printf(" "); 18 | printf("%d", ara[dq.front()]); 19 | while(!dq.empty() && dq.front() <= i-k+1) dq.pop_front(); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/01/Totient Sieve.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 2000100 3 | int phi[MAX] ; 4 | void sievePHI(){ 5 | long long i,j; 6 | for( i=2;i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | mapmp; 7 | 8 | mp[10] = 11; 9 | mp[20] = 21; 10 | mp[30] = 31; 11 | mp[10]++; 12 | mp[20] = 0; 13 | mp.erase(20); 14 | 15 | cout << mp.size() << endl; 16 | 17 | map:: iterator it = mp.lower_bound(21); 18 | 19 | cout << it->first << ' ' << it->second << endl; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/03/Int To Excel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | ///A is 1 based 6 | string intToExcel(int A) { 7 | string ans; 8 | 9 | while(true) { 10 | A--; 11 | ans += (A%26) + 'A'; 12 | A /= 26; 13 | if(!A) break; 14 | } 15 | 16 | reverse(ans.begin(), ans.end()); 17 | return ans; 18 | } 19 | 20 | int main() { 21 | int a; 22 | while(cin >> a) { 23 | cout << intToExcel(a) << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/04/LIS Binary search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 100005 3 | #define MAX 100000 4 | 5 | using namespace std; 6 | 7 | int n, a[LIM], L[LIM]; 8 | 9 | int LIS() { 10 | memset(L, 127, sizeof L); 11 | 12 | int ans = 0; 13 | for(int i=1; i<=n; i++) { 14 | int x = lower_bound(L+1, L+MAX+1, a[i]) - L; 15 | ans = max(ans, x); 16 | L[x] = min(L[x], a[i]); 17 | } 18 | return ans; 19 | } 20 | 21 | int main() { 22 | scanf("%d", &n); 23 | for(int i=1; i<=n; i++) scanf("%d", &a[i]); 24 | 25 | cout << LIS() << endl; 26 | } 27 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/04/LIS Set.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 100005 3 | #define MAX 100000 4 | 5 | using namespace std; 6 | 7 | int n, a[LIM]; 8 | setL; 9 | 10 | int LIS() { 11 | L.clear(); 12 | 13 | for(int i=1; i<=n; i++) { 14 | set::iterator it = L.lower_bound(a[i]); 15 | if(it != L.end()) L.erase(it); 16 | L.insert(a[i]); 17 | 18 | } 19 | return L.size(); 20 | } 21 | 22 | int main() { 23 | scanf("%d", &n); 24 | for(int i=1; i<=n; i++) scanf("%d", &a[i]); 25 | 26 | cout << LIS() << endl; 27 | } 28 | -------------------------------------------------------------------------------- /Algo_DS_Code_Library/rantree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 200 3 | #define MAX 20 4 | #define MXX 50 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | srand(time(NULL)); 10 | 11 | freopen("in.txt", "w", stdout); 12 | 13 | int n = rand() % LIM + 2; 14 | int q = rand() % LIM + 2; 15 | scanf("%d", &n); 16 | cout << n << ' ' << q << endl; 17 | 18 | for(int i=2; i<=n; i++) { 19 | int j = rand() % (i-1) + 1; 20 | cout << i << ' ' << j << ' ' << rand()%MAX+1 << endl; 21 | } 22 | 23 | while(q--) { 24 | int u = rand() % n + 1; 25 | int w = rand() % (MXX) + 1; 26 | 27 | cout << u << ' ' << w << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces/Gym/100589F. Count Ways.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int grid[100][100]; 6 | 7 | int main() { 8 | for(int i=0; i<10; i++) grid[i][0] = grid[0][i] = 1; 9 | for(int i=1; i<10; i++) { 10 | for(int j=1; j<10; j++) { 11 | grid[i][j] = grid[i-1][j] + grid[i][j-1]; 12 | } 13 | } 14 | 15 | for(int i=0; i<10; i++) { 16 | for(int j=0; j<10; j++) printf("%6d", grid[i][j]); 17 | cout << endl; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Codeforces/Gym/100820G. Racing Gems.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define vl vector 4 | #define pll pair 5 | #define vp vector 6 | #define pb(x) push_back(x) 7 | 8 | using namespace std; 9 | 10 | int main() { 11 | int n; 12 | ll x,y; 13 | vl pts; 14 | vp seg; 15 | scanf("%d", &n); 16 | for(int i=0; i 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Gym/101021A. Guess the Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int lo = 1, hi = 1000000, md; 7 | char ans[4]; 8 | 9 | while(lo < hi) { 10 | md = (lo+hi + 1) / 2; 11 | printf("%d\n", md); 12 | // printf("%d %d %d\n", lo, md, hi); 13 | fflush(stdout); 14 | 15 | scanf("%s", ans); 16 | if(ans[0] == '<') hi = md-1; 17 | else lo = md; 18 | } 19 | 20 | printf("! %d\n", lo); 21 | fflush(stdout); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Codeforces/Practice/001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | scanf("%d", &n); 7 | if(!(n%2) && n!=2) printf("YES\n"); 8 | else printf("NO\n"); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Practice/002.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n; 6 | scanf("%lld", &n); 7 | if(n%2) printf("-%lld\n", (n+1)/2 ); 8 | else printf("%lld\n", (n+1)/2); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Practice/003.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, a,b,c, x=0,y=0,z=0; 6 | 7 | scanf("%d", &n); 8 | 9 | while(n--) 10 | { 11 | scanf("%d %d %d", &a, &b, &c); 12 | x+=a; y+=b; z+=c; 13 | } 14 | 15 | if(!x && !y && !z) printf("YES\n"); 16 | else printf("NO\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Codeforces/Practice/006C. Alice, Bob and Chocolate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int tim[100005]; 6 | 7 | int main() { 8 | 9 | int n; 10 | scanf("%d", &n); 11 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | string num; 8 | cin >> num; 9 | int sz = num.size(); 10 | 11 | int p = 1, ans = 0, i; 12 | for(i=0; i=0; i--) { 18 | ans += num[i]*p; 19 | p *= 2; 20 | } 21 | 22 | printf("%d\n", ans); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Practice/018C. Stripe.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, ara[100005]; 8 | scanf("%d", &n); 9 | ara[0] = 0; 10 | for(int i=1; i<=n; i++) { 11 | scanf("%d", &ara[i]); 12 | ara[i] += ara[i-1]; 13 | } 14 | 15 | int ans = 0; 16 | for(int i=1; i 2 | #define pii pair 3 | #define ff first 4 | #define ss second 5 | #define mpr make_pair 6 | #define LIM 100000 7 | #define MAX 1000000000 8 | #define MOD 1000000007 9 | 10 | using namespace std; 11 | 12 | int n,m; 13 | pii bus[LIM+100]; 14 | int dp[LIM+100]; 15 | 16 | int f(int in) { 17 | if(in == m) { 18 | 19 | } 20 | if(dp[in] != -1) return dp[in]; 21 | 22 | } 23 | 24 | int main() { 25 | scanf("%d %d", &n,&m); 26 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a,b; 7 | cin >> a >> b; 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Practice/1060 - nth Permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n, sz, alphaCount[100]; 6 | string seq; 7 | 8 | int dp[] 9 | 10 | int getNth(int indx) { 11 | 12 | 13 | 14 | } 15 | 16 | 17 | 18 | 19 | int main() { 20 | 21 | int T; 22 | scanf("%d", &T); 23 | for(int t=1; t<=T; t++) { 24 | 25 | memset(alphaCount, 0, sizeof(alphaCount)); 26 | memset(dp, -1, sizeof(dp)); 27 | 28 | cin >> seq; 29 | scanf("%d", &n); 30 | 31 | sz = seq.size(); 32 | for(int i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | char s1[110], s2[110]; 10 | 11 | scanf("%s", s1); 12 | scanf("%s", s2); 13 | 14 | for(int i=0; s1[i]!='\0'; i++) 15 | s1[i]=toupper(s1[i]); 16 | for(int i=0; s2[i]!='\0'; i++) 17 | s2[i]=toupper(s2[i]); 18 | 19 | printf("%d\n", strcmp(s1, s2)); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Practice/118A. String Task.py: -------------------------------------------------------------------------------- 1 | word = input() 2 | 3 | sz = len(word) 4 | 5 | word = word.lower() 6 | 7 | ans = "" 8 | 9 | for i in range(sz): 10 | if word[i] == 'y' or word[i] == 'a' or word[i] == 'e' or word[i] == 'i' or word[i] == 'o' or word[i] == 'u': 11 | continue 12 | ans += "." + word[i] 13 | 14 | print(ans) 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Codeforces/Practice/118A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char c; 9 | while(scanf("%c", &c) && c!='\n') 10 | { 11 | c=tolower(c); 12 | if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y') continue; 13 | 14 | printf(".%c", c); 15 | } 16 | 17 | printf("\n"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Practice/124A.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,a,b; 6 | scanf("%d %d %d", &n,&a,&b); 7 | 8 | if(a+b == n) printf("%d\n", b); 9 | else printf("%d\n", b+1); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Practice/133A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int i; 9 | char s[110]; 10 | scanf("%s", &s); 11 | 12 | for(i=0; s[i]!='\0'; i++) 13 | { 14 | if(s[i]=='H' || s[i]=='Q' || s[i]=='9') 15 | { 16 | printf("YES\n"); 17 | return 0; 18 | } 19 | } 20 | printf("NO\n"); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Codeforces/Practice/137C. History.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pii pair 3 | 4 | using namespace std; 5 | 6 | bool comp(pii a, pii b) { 7 | 8 | return a.second > b.second; 9 | } 10 | 11 | int main() { 12 | 13 | int n; 14 | scanf("%d", &n); 15 | pii tim[100005]; 16 | for(int i=0; i l) cnt++; 27 | else l = tim[i].first; 28 | } 29 | 30 | printf("%d\n", cnt); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces/Practice/144A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, num[205]; 8 | int lowVal = INT_MAX, lowIn, hiVal = INT_MIN, hiIn; 9 | 10 | scanf("%d", &n); 11 | for(int i=0; i hiVal) { 18 | hiVal = num[i]; 19 | hiIn = i; 20 | } 21 | } 22 | 23 | if(hiIn < lowIn) { 24 | printf("%d\n", hiIn + n - lowIn - 1); 25 | } 26 | else { 27 | printf("%d\n", hiIn + n - lowIn -1 -1); 28 | } 29 | 30 | return 0; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Practice/152C. Pocket Book.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define MOD 1000000007 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int n,m; 9 | scanf("%d %d", &n,&m); 10 | 11 | string names[102]; 12 | for(int i=0; i> names[i]; 13 | 14 | int alpha[100]; 15 | 16 | ll ans = 1; 17 | for(int i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n,k, ara[100], i,j; 9 | scanf("%d %d", &n, &k); 10 | 11 | for(i=1; i<=n; i++) scanf("%d", &ara[i]); 12 | 13 | if(ara[k] > 0) 14 | { 15 | while(ara[k] == ara[k+1]) 16 | k++; 17 | printf("%d\n", k); 18 | } 19 | else 20 | { 21 | while(ara[k] <= 0 && k>0) 22 | k--; 23 | printf("%d\n", k); 24 | } 25 | 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/Practice/161D. Distance in Tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 50004 3 | #define vi vector 4 | #define pb(x) push_back(x) 5 | 6 | using namespace std; 7 | 8 | int n, k, ans=0; 9 | int dp[LIM][505]; 10 | vi g[LIM]; 11 | 12 | void f(int u, int p) { 13 | dp[u][0] = 1; 14 | for(int v : g[u]) { 15 | if(v == p) continue; 16 | f(v, u); 17 | for(int i=0; i 2 | #define LIM 2000006 3 | #define ll long long int 4 | 5 | using namespace std; 6 | 7 | int k,n, cnt[LIM]; 8 | char str[LIM]; 9 | string seq; 10 | 11 | int main() { 12 | scanf("%d", &k); 13 | cin >> seq; 14 | 15 | seq = "0" + seq; 16 | 17 | for(int i=1; i 2 | #define MOD 1000000007 3 | #define LIM 10000007 4 | #define ll long long int 5 | 6 | using namespace std; 7 | 8 | int n; 9 | ll dp[LIM]; 10 | 11 | ll getCount(int n) { 12 | 13 | if(!n) return 1; 14 | else if(n < 0) return 0; 15 | 16 | if(dp[n] != 0) return dp[n]; 17 | 18 | return dp[n] = (getCount(n-2) + 2*getCount(n-1))%MOD; 19 | } 20 | 21 | int main() { 22 | 23 | scanf("%d", &n); 24 | 25 | if(!n) printf("0\n"); 26 | else printf("%lld\n", 3*getCount(n-2)); 27 | 28 | return 0; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Practice/166E. Tetrahedron iterative.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 1000000007 3 | #define LIM 10000007 4 | #define ll long long int 5 | 6 | using namespace std; 7 | 8 | int n; 9 | ll temp, takeD, takeO; 10 | 11 | int main() { 12 | 13 | scanf("%d", &n); 14 | 15 | takeD = 0; 16 | takeO = 1; 17 | 18 | for(int i=2; i<=n; i++) { 19 | temp = takeD; 20 | takeD = 3*takeO; 21 | takeO = 2*takeO + temp; 22 | 23 | 24 | while(takeD >= MOD) takeD -= MOD; 25 | while(takeO >= MOD) takeO -= MOD; 26 | } 27 | 28 | printf("%lld\n", takeD); 29 | 30 | return 0; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Practice/166E. Tetrahedron.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 1000000007 3 | #define LIM 10000007 4 | #define ll long long int 5 | 6 | using namespace std; 7 | 8 | int n; 9 | ll dp[LIM][3]; 10 | 11 | ll getCount(int n, int lastA) { 12 | 13 | if(!n) { 14 | if(lastA) return 1; 15 | else return 0; 16 | } 17 | // else if(n < 0) return 0; 18 | 19 | if(dp[n][lastA] != 0) return dp[n][lastA]; 20 | 21 | if(lastA) return dp[n][lastA] = (3*getCount(n-1, !lastA) )%MOD; 22 | else return dp[n][lastA] = (getCount(n-1, !lastA) + 2*getCount(n-1, lastA) ) % MOD; 23 | } 24 | 25 | int main() { 26 | 27 | scanf("%d", &n); 28 | 29 | if(!n) printf("0\n"); 30 | else printf("%lld\n", getCount(n, 1)); 31 | 32 | return 0; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Codeforces/Practice/197A. Plate Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a,b,r; 7 | cin >> a >> b >> r; 8 | if(min(a,b) < 2*r) cout << "Second" << endl; 9 | else cout << "First" << endl; 10 | } 11 | -------------------------------------------------------------------------------- /Codeforces/Practice/1A.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | long long int n,m,a; 7 | scanf("%lld %lld %lld", &n, &m, &a); 8 | 9 | printf("%lld\n", ((m+a-1)/a) * ((n+a-1)/a)); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Practice/220A. Little Elephant and Problem 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, t; 8 | scanf("%d", &n); 9 | int ara1[100005], ara2[100005]; 10 | for(int i=0; i 2 | #define ll long long int 3 | #define MX 1000000 4 | using namespace std; 5 | 6 | int n; 7 | ll num, t; 8 | 9 | bool notPrime[1000006]; 10 | 11 | void sv() { 12 | 13 | notPrime[1] = true; 14 | for(int i=4; i<=MX; i+=2) notPrime[i] = true; 15 | for(int i=3; i<=1003; i+=2) { 16 | for(int j=i+i; j<=MX; j+=i) { 17 | notPrime[j] = true; 18 | } 19 | } 20 | } 21 | 22 | int main() { 23 | 24 | sv(); 25 | 26 | scanf("%d", &n); 27 | while(n--) { 28 | 29 | scanf("%lld", &num); 30 | t = sqrt(num); 31 | if(!notPrime[t] && t*t==num) printf("YES\n"); 32 | else printf("NO\n"); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Codeforces/Practice/231A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a,b,c, s, cnt=0; 9 | scanf("%d", &n); 10 | 11 | while(n--) 12 | { 13 | scanf("%d %d %d", &a,&b,&c); 14 | s=a+b+c; 15 | if(s>1) cnt++; 16 | } 17 | 18 | printf("%d\n", cnt); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Practice/257B. Playing Cubes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n,m; 8 | scanf("%d %d", &n,&m); 9 | if(n < m) swap(n,m); 10 | 11 | printf("%d %d\n", n-1, m); 12 | 13 | return 0; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Codeforces/Practice/258A. Little Elephant and Bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | int n; 8 | cin >> s; 9 | n = s.size(); 10 | 11 | int in = 0; 12 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | string seq; 8 | cin >> seq; 9 | int sz = seq.size(); 10 | 11 | vector l,r; 12 | 13 | for(int i=0; i=0; i--) printf("%d\n", l[i]); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/Practice/266B. Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n,t; 8 | string seq; 9 | cin >> n >> t; 10 | cin >> seq; 11 | int sz = seq.size(); 12 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | long long int n; 6 | scanf("%lld", &n); 7 | printf("%lld\n", n*( n*n +5 )/6); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Codeforces/Practice/276C. Little Girl and Maximum Sum efficient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MX 2000006 3 | #define ll long long int 4 | using namespace std; 5 | 6 | int n,q,l,r, ara[MX], freq[MX]; 7 | 8 | int main() { 9 | 10 | scanf("%d %d", &n,&q); 11 | for(int i=1; i<=n; i++) scanf("%d", &ara[i]); 12 | sort(ara+1, ara+n+1); 13 | freq[0] = 0; 14 | for(int i=0; i 2 | #define LIM 200005 3 | #define vi vector 4 | #define pb push_back 5 | 6 | using namespace std; 7 | 8 | int n, sub[LIM], vis[LIM], ; 9 | vi g[LIM]; 10 | 11 | int main() { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Codeforces/Practice/281A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char c, s[1010]; 9 | scanf("%c", &c); 10 | printf("%c", toupper(c)); 11 | gets(s); 12 | printf("%s\n", s); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Codeforces/Practice/292E. Copying Data.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 100005 3 | 4 | using namespace std; 5 | 6 | int n, a[LIM], b[LIM], segTree[4*LIM]; 7 | 8 | void update(int node, int st, int ed, int l, int r, int x, int k) { 9 | if(ed < l || st > r) return; 10 | if(st >= l && ed <= r) { 11 | segTree[node] = l - st + x; 12 | } 13 | } 14 | 15 | int main() { 16 | scanf("%d %d", &n, &m); 17 | for(int i=1; i<=n; i++) scanf("%d", &a[i]); 18 | for(int i=1; i<=n; i++) scanf("%d", &b[i]); 19 | 20 | while(m--) { 21 | scanf("%d", &c); 22 | if(c == 1) { 23 | scanf("%d %d %d", &x,&y,&k); 24 | update(1, 1,n, y, y+k, x,k); 25 | } 26 | else { 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Practice/2B. The least round way.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n; 6 | int dp[1010]; 7 | 8 | int main() { 9 | scanf("%d", &n); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Practice/318A.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n, k, h; 6 | scanf("%lld %lld", &n, &k); 7 | 8 | h=(n+1)/2; 9 | 10 | if(k <= h) printf("%lld\n", 2*k - 1); 11 | else printf("%lld\n", 2*(k-h)); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Practice/319B. Psychos in a Line.c: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Codeforces/Practice/339A. Helpful Maths.py: -------------------------------------------------------------------------------- 1 | n = input().split("+") 2 | n.sort() 3 | sol = "" 4 | 5 | for i in range(len(n)): 6 | if i != 0: sol += "+" 7 | sol += n[i] 8 | 9 | print(sol) -------------------------------------------------------------------------------- /Codeforces/Practice/339B. Xenia and Ringroad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, m, task[100005]; 8 | cin >> n >> m; 9 | for(int i=1; i<=m; i++) scanf("%d", &task[i]); 10 | task[0] = 1; 11 | 12 | long long int ans = 0; 13 | for(int i=1; i<=m; i++) ans += (task[i] - task[i-1] + n) % n; 14 | cout << ans << endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Practice/348A. Mafia.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, x, mx = INT_MIN; 8 | long long int tot = 0; 9 | scanf("%d", &n); 10 | for(int i=0; i mx) printf("%I64d\n", ans); 22 | else printf("%d\n", mx); 23 | 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Practice/367B. Sereja ans Anagrams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 200005 3 | 4 | using namespace std; 5 | 6 | int n,m,p, a[LIM], b[LIM]; 7 | mapgoal, cur; 8 | 9 | int main() { 10 | scanf("%d %d %d", &n, &m, &p); 11 | for(int i=0; i= n: return n 8 | cap = a[cur] - val[cur] 9 | if(cap > v): 10 | val[cur] += v 11 | return cur 12 | else: 13 | val[cur] += cap 14 | nxt[cur] = f(nxt[cur], v-cap) 15 | return nxt[cur] 16 | 17 | 18 | q = int(input()) 19 | while q > 0: 20 | q = q-1 21 | c = [int(i) for i in input().split()] 22 | if c[0] == 1: 23 | # print(c[1], c[2]) 24 | f(c[1]-1, c[2]) 25 | else: 26 | # x = int(input()) 27 | print(val[ c[1]-1 ]) 28 | 29 | # print(val) -------------------------------------------------------------------------------- /Codeforces/Practice/388A. Fox and Box Accumulation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, w[102]; 8 | scanf("%d", &n); 9 | for(int i=0; iq; 14 | q.push(0); 15 | 16 | int ans = 0; 17 | for(int x=0; x= uW && !vis[i]) { 23 | uW++; 24 | vis[i] = 1; 25 | } 26 | } 27 | ans++; 28 | } 29 | } 30 | 31 | printf("%d\n", ans); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Codeforces/Practice/401A.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | long long int n, k, cards, sum=0; 7 | scanf("%lld %lld", &n, &k); 8 | while(n--) 9 | { 10 | scanf("%lld", &cards); 11 | sum+=cards; 12 | } 13 | if(sum>=0) printf("%lld\n", ((sum) +k - 1)/k ); 14 | else printf("%lld\n", ((-sum) +k - 1)/k ); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Practice/414A. Mashmokh and Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n,k; 8 | 9 | scanf("%d %d", &n, &k); 10 | 11 | int p = n/2; 12 | 13 | if(n == 1 && k == 0) { 14 | printf("1\n"); 15 | return 0; 16 | } 17 | 18 | if(k < p || n == 1) { 19 | printf("-1\n"); 20 | return 0; 21 | } 22 | 23 | else { 24 | 25 | int t = k-p ; 26 | int i = 0; 27 | if(t) printf("%d %d ", t+1, (t+1)*2), i = 2; 28 | int c = (t+1)*2+1; 29 | if(i < n) { 30 | 31 | printf("%d", c++); i++; 32 | } 33 | for(; i 2 | #define ll long long int 3 | #define LIM 2000 4 | #define MOD 1000000007 5 | 6 | using namespace std; 7 | 8 | int n,k; 9 | ll dp[LIM+10][LIM+10]; 10 | 11 | ll getComb(int indx, int last) { 12 | 13 | if(indx == k) return 1; 14 | if(dp[indx][last] != -1) return dp[indx][last]; 15 | 16 | ll ans = 0; 17 | for(int i=last; i<=n; i+=last) { 18 | ans = (ans + getComb(indx+1, i) ) % MOD; 19 | } 20 | 21 | return dp[indx][last] = ans; 22 | } 23 | 24 | int main() { 25 | 26 | memset(dp, -1, sizeof(dp)); 27 | 28 | cin >> n >> k ; 29 | cout << getComb(0, 1) << endl; 30 | 31 | return 0; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces/Practice/424C. Magic Formulas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | ll n,ara[1000006]; 6 | ll cumXor[1000006]; 7 | 8 | int main() { 9 | 10 | scanf("%lld", &n); 11 | for(ll i=1; i<=n; i++) scanf("%lld", &ara[i]); 12 | 13 | for(ll i=1; i<=n; i++) cumXor[i] = cumXor[i-1] ^ i; 14 | 15 | ll res = 0; 16 | for(ll i=1; i<=n; i++) { 17 | 18 | if((n/i) % 2) res ^= cumXor[i-1]; 19 | 20 | res ^= cumXor[n%i] ^ ara[i]; 21 | } 22 | 23 | printf("%lld\n", res); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Practice/448D. Multiplication Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n,m,k; 7 | 8 | bool f(ll x) { 9 | ll ans = 0; 10 | for(int i=1; i<=min(x, n); i++) { 11 | ans += min( m, x/i ); 12 | if(ans >= k) return true; 13 | } 14 | return false; 15 | } 16 | 17 | int main() { 18 | cin >> n >> m >> k; 19 | // scanf("%I64d %I64d %I64d", &n,&m,&k); 20 | ll hi = n*m; 21 | ll lo = 1; 22 | 23 | while(lo < hi) { 24 | ll md = (lo+hi)/2; 25 | // cout << lo << ' ' << hi << ' ' << md << endl; 26 | if(f(md)) hi = md; 27 | else lo = md+1; 28 | } 29 | // printf("%I64d\n", hi); 30 | cout << hi << endl; 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/Practice/451D. Count Good Substrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string str; 7 | cin >> str; 8 | int cnt[3][3] = {0}; 9 | long long int ans[3] = {0}; 10 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | long long int n, sum[500005], totalSum=0; 6 | 7 | int main() { 8 | 9 | scanf("%I64d", &n); 10 | sum[0] = 0; 11 | for(int i=1; i<=n; i++) { 12 | scanf("%I64d", &sum[i]); 13 | totalSum += sum[i]; 14 | sum[i] += sum[i-1]; 15 | } 16 | 17 | if(totalSum%3) { 18 | printf("0\n"); 19 | return 0; 20 | } 21 | 22 | totalSum /= 3; 23 | long long int ans = 0, tmp = 0; 24 | 25 | if(sum[1] == totalSum) tmp++; 26 | for(int i=2; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | -------------------------------------------------------------------------------- /Codeforces/Practice/467A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a,b, cnt=0; 9 | scanf("%d", &n); 10 | while(n--) 11 | { 12 | scanf("%d %d", &a,&b); 13 | if(b-1>2) cnt++; 14 | } 15 | printf("%d\n", cnt); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Codeforces/Practice/467B. Fedor and New Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n,m,k, army[1010], diff[23], ans=0; 8 | memset(diff, 0, sizeof(diff)); 9 | 10 | scanf("%d %d %d", &n,&m,&k); 11 | for(int i=0; i<=m; i++) scanf("%d", &army[i]); 12 | 13 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | long long int n,m; 8 | scanf("%I64d %I64d", &n, &m); 9 | 10 | long long int tm1 = n%m; 11 | long long int div = n/m; 12 | 13 | long long int minimum = (m-tm1) * div*(div-1)/2 + tm1 * div*(div+1)/2; 14 | long long int maximum = (n - m + 1)*(n-m)/2; 15 | 16 | printf("%I64d %I64d\n", minimum, maximum); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Codeforces/Practice/478C. Table Decorations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ll col[4]; 8 | cin >> col[0] >> col[1] >> col[2]; 9 | 10 | sort(col, col+3); 11 | 12 | cout << min(col[0]+col[1], (col[0]+col[1]+col[2])/3) << endl; 13 | 14 | //y = min( (b-g)/2, r-g ); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Codeforces/Practice/485A. Factory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | ll a,d,m, i = 1e7; 8 | scanf("%lld %lld", &a, &m); 9 | 10 | do { 11 | d = a%m; 12 | a += d; 13 | // cout << a << ' ' << d << endl; getchar(); 14 | } while(d && i--); 15 | 16 | if(d) printf("No\n"); 17 | else printf("Yes\n"); 18 | } 19 | -------------------------------------------------------------------------------- /Codeforces/Practice/493D. Vasya and Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | //Compiler version g++ 4.9 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | if(n%2) cout << "black" << endl; 10 | else cout << "white\n1 2" << endl; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Codeforces/Practice/498A. Crazy Town.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 303 3 | #define ll long long int 4 | 5 | using namespace std; 6 | 7 | int n; 8 | ll x,y, X,Y; 9 | ll a, b, c; 10 | 11 | int f(ll x, ll y) { 12 | ll v = a*x + b*y + c; 13 | if(v > 0) return 1; 14 | return -1; 15 | } 16 | 17 | int main() { 18 | scanf("%lld %lld", &x,&y); 19 | scanf("%lld %lld", &X,&Y); 20 | scanf("%d", &n); 21 | int ans = 0; 22 | for(int i=0; i 2 | #define sqr(x) ( (x) * (x) ) 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double r, x,y, X,Y; 8 | scanf("%lf %lf %lf %lf %lf", &r, &x,&y, &X,&Y); 9 | 10 | double d = sqrt( sqr(x-X) + sqr(y-Y) ); 11 | 12 | double t = d / (2*r); 13 | 14 | // cout << "T " << t << endl; 15 | 16 | printf("%d\n", (int)(ceil(t)) ); 17 | 18 | // if( floor(t) == t ) printf("%d\n", (int)t ); 19 | // else printf("%d\n", (int)(floor(t)+2) ); 20 | 21 | // main(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Practice/509C. Sums of Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Codeforces/Practice/515A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a,b,s, t; 9 | scanf("%d %d %d", &a, &b, &s); 10 | 11 | t= abs(a) + abs(b); 12 | 13 | if( s>=t && ( (t%2 && s%2) || (!(t%2) && !(s%2) )) ) printf("Yes\n"); 14 | else printf("No\n"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Practice/519C. A and B and Team Training.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n,m, ans = 0; 7 | cin >> n >> m; 8 | 9 | while( n && m && (n >= 2 || m >= 2) ) { 10 | if(n > m) { 11 | n -= 2; m--; 12 | ans++; 13 | } 14 | else { 15 | n--; m -= 2; 16 | ans++; 17 | } 18 | } 19 | 20 | cout << ans << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Practice/53C. Little Frog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | scanf("%d", &n); 8 | int i=1,j=n; 9 | 10 | int in = 1; 11 | 12 | while(i <= j) { 13 | if(in) printf("%d ", i++); 14 | else printf("%d ", j--); 15 | in ^= 1; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Codeforces/Practice/552C. Vanya and Scales.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define vl vector 4 | #define pb(x) push_back(x) 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ll w,m, a[70] = {0}; 10 | cin >> w >> m; 11 | 12 | int in=0; 13 | while(m) { 14 | a[in++] = m%w; 15 | m /= w; 16 | } 17 | 18 | for(int i=0; i<=in; i++) { 19 | // cout << i << ' ' << a[i] << endl; 20 | if(a[i] < 2) continue; 21 | if(a[i] == w-1 || a[i] == w) { 22 | a[i+1]++; 23 | } 24 | else { 25 | cout << "NO" << endl; 26 | return 0; 27 | } 28 | } 29 | 30 | cout << "YES" << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Practice/578B. Or Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 200005 3 | #define ll long long int 4 | 5 | using namespace std; 6 | 7 | int n,k,x; 8 | ll a[LIM], b[LIM], c[LIM]; 9 | 10 | int main() { 11 | scanf("%d %d %d", &n, &k,&x); 12 | 13 | for(int i=1; i<=n; i++) scanf("%lld", &a[i]); 14 | for(int i=1; i<=n; i++) b[i] = b[i-1] | a[i]; 15 | for(int i=n; i>=0; i--) c[i] = c[i+1] | a[i]; 16 | 17 | ll ans = 0; 18 | ll mul = 1; 19 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int n, a[250005]; 6 | mapcnt; 7 | vectorans; 8 | 9 | int main() { 10 | scanf("%d", &n); 11 | for(int i=0; i=0; i--) { 19 | if(cnt[ a[i] ]) { 20 | cnt[ a[i] ]--; 21 | for(int p : ans) cnt[ __gcd(a[i], p) ]-=2; 22 | ans.push_back(a[i]); 23 | } 24 | } 25 | 26 | for(int p : ans) cout << p << ' '; cout << endl; 27 | } 28 | -------------------------------------------------------------------------------- /Codeforces/Practice/616D. Longest k-Good Segment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 1000006 3 | 4 | using namespace std; 5 | 6 | int n,k, a[MAX], cnt[MAX]; 7 | 8 | int main() { 9 | scanf("%d %d", &n, &k); 10 | for(int i=1; i<=n; i++) scanf("%d", &a[i]); 11 | 12 | int i=1, j=1; 13 | int cur = 0; 14 | int sz=-1, b,c; 15 | 16 | while(j <= n) { 17 | if(!cnt[ a[j] ]) cur++; 18 | cnt[ a[j] ]++; 19 | 20 | while(cur > k) { 21 | if(cnt[ a[i] ] == 1) cur--; 22 | cnt[ a[i] ]--; 23 | i++; 24 | } 25 | 26 | if(j-i+1 > sz) { 27 | sz = j-i+1; 28 | b = i; c = j; 29 | } 30 | 31 | j++; 32 | } 33 | 34 | cout << b << ' ' << c << endl; 35 | } 36 | -------------------------------------------------------------------------------- /Codeforces/Practice/630H. Benches.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define sqr(x) ( (x) * (x) ) 4 | 5 | using namespace std; 6 | 7 | ll n; 8 | 9 | int main() { 10 | scanf("%lld", &n); 11 | 12 | ll ans = sqr( n*(n-1)*(n-2)*(n-3)*(n-4) / (5*4*3*2*1) ) * (5*4*3*2*1); 13 | 14 | printf("%lld\n", ans ); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Codeforces/Practice/650A. Watchmen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pii pair 3 | #define ll long long int 4 | 5 | using namespace std; 6 | 7 | mapvisx,visy; 8 | mapcntx,cnty; 9 | mapcnt; 10 | 11 | int n,x,y; 12 | 13 | int main() { 14 | scanf("%d", &n); 15 | ll ans = 0; 16 | for(int i=0; i 0 : 4 | n -= 1 5 | word = input() 6 | sz = len(word) 7 | if sz > 10 : 8 | print(word[0] + str(sz-2) + word[sz-1]) 9 | else : 10 | print(word) 11 | 12 | -------------------------------------------------------------------------------- /Codeforces/Practice/722D. Generating Sets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,a; 6 | setY; 7 | 8 | int main() { 9 | scanf("%d", &n); 10 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | ll n; 9 | cin >> n; 10 | 11 | 12 | // cout << log2(n) << endl; 13 | cout << ceil( log2(n) ) << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Codeforces/Practice/738A. Interview with Oleg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n; 8 | string s; 9 | char ans[105]; 10 | cin >> n; 11 | cin >> s; 12 | int j=0; 13 | for(int i=0; i 2 | #define vi vector 3 | #define pb(x) push_back(x) 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int a,b,g,n, l,r, sq; 9 | vi div; 10 | 11 | scanf("%d %d %d", &a,&b,&n); 12 | 13 | g = __gcd(a,b); 14 | sq = sqrt(g); 15 | for(int i=1; i<=sq; i++) { 16 | if(g%i==0) { 17 | div.pb(i); 18 | div.pb(g/i); 19 | } 20 | } 21 | sort(div.begin(), div.end()); 22 | 23 | while(n--) { 24 | scanf("%d %d", &l,&r); 25 | int x = upper_bound(div.begin(), div.end(), r) - div.begin(); 26 | x--; 27 | if(x >= 0 && l <= div[x] && div[x] <= r) printf("%d\n", div[x]); 28 | else printf("-1\n"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Practice/763B. Timofey and rectangles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n; 8 | cin >> n; 9 | 10 | cout << "YES" << endl; 11 | 12 | while(n--) { 13 | int x1,y1,x2,y2; 14 | cin >> x1 >> y1 >> x2 >> y2; 15 | 16 | if(abs(x1)%2==1 && abs(y1)%2==1) cout << 1 << endl; 17 | else if(abs(x1)%2==0 && abs(y1)%2==1) cout << 2 << endl; 18 | else if(abs(x1)%2==1 && abs(y1)%2==0) cout << 3 << endl; 19 | else cout << 4 << endl; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Practice/77B. Falling Anvils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int t; 8 | scanf("%d", &t); 9 | while(t--) { 10 | ll a,b; 11 | scanf("%lld %lld", &a,&b); 12 | if(!b) printf("1\n"); 13 | else if(!a) printf("0.5\n"); 14 | else if(1.0*a/4 <= b) printf("%.8f\n", 1.0*(a+8*b)/(16*b)); 15 | else printf("%.8f\n", 1.0*(a-b)/a); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Practice/797C. Minimal string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string a,b,c, mn; 7 | cin >> a; 8 | 9 | mn = a; 10 | for(int i=mn.size()-2; i>=0; i--) { 11 | mn[i] = min(mn[i], mn[i+1]); 12 | } 13 | 14 | // cout << mn << endl; 15 | 16 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int main() { 8 | int n, a, u=0,v=0; 9 | scanf("%d", &n); 10 | for(int i=0; i 2 | #define lim 15 3 | #define mx 15 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | srand(time(NULL)); 10 | 11 | int n = rand() % lim; 12 | cout << n << endl; 13 | 14 | int last = 0; 15 | 16 | while(n) { 17 | int x = rand() % mx; 18 | // if(x >= last) { 19 | cout << x << ' '; 20 | last = x; 21 | n--; 22 | // } 23 | } 24 | cout << endl; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Practice/888D. Almost Identity Permutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n,k; 7 | 8 | int main() { 9 | scanf("%lld %lld", &n,&k); 10 | 11 | ll ans = 1; 12 | if(k >= 2) ans += n*(n-1)/2; 13 | if(k >= 3) ans += n*(n-1)*(n-2)/6 * 2; 14 | if(k >= 4) ans += n*(n-1)*(n-2)*(n-3)/24 * 9; 15 | 16 | // memset(dp, -1, sizeof dp); 17 | cout << ans << endl; 18 | 19 | // main(); 20 | 21 | } 22 | 23 | /* 24 | 4 1 25 | 1 26 | 27 | 4 2 28 | 7 29 | 30 | 5 3 31 | 31 32 | 33 | 5 4 34 | 76 35 | */ 36 | -------------------------------------------------------------------------------- /Codeforces/Practice/946E. Largest Beautiful Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | scanf("%d", &t); 8 | while(t--) { 9 | 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /Codeforces/Practice/965D. Single-use Stones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,w, a[100005]; 6 | 7 | int main() { 8 | scanf("%d %d", &w, &n); 9 | for(int i=1; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char f=-1, str[200]; 9 | int cnt=0; 10 | scanf("%s", str); 11 | for(int i=0; str[i]!='\0'; i++) 12 | { 13 | if(f!=str[i]) 14 | { 15 | f=str[i]; 16 | cnt=1; 17 | } 18 | else 19 | { 20 | cnt++; 21 | } 22 | if(cnt==7) 23 | { 24 | printf("YES\n"); 25 | return 0; 26 | } 27 | } 28 | printf("NO\n"); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Practice/asdsad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | char str[1000]; 6 | 7 | int main() 8 | { 9 | gets(str); 10 | printf("%s",str); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Practice/deb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 200000 3 | 4 | using namespace std; 5 | 6 | string seq, code = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 7 | 8 | int main() { 9 | // cout << code.size() << endl; 10 | srand(time(NULL)); 11 | 12 | freopen("test.txt", "w", stdout); 13 | 14 | int n,m = 1; 15 | 16 | cout << LIM << ' ' << 1 << endl; 17 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | mapmp; 7 | 8 | mp[10] = 1001; 9 | mp[32] = 1e9; 10 | mp[100] = 10101010; 11 | mp[16] = 1; 12 | 13 | map::iterator it = mp.end(); 14 | it--; 15 | 16 | cout << it->first << ' ' << it->second << endl; 17 | 18 | mp[100] -= 10101010; 19 | 20 | mp.erase(100); 21 | 22 | it = mp.end(); it--; 23 | 24 | // mp.erase(100); 25 | 26 | 27 | cout << it->first << ' ' << it->second << endl; 28 | // cout << it->first << ' ' << it->second << endl; 29 | // cout << it->first << ' ' << it->second << endl; 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Practice/table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define vii vector 3 | #define pb push_back 4 | 5 | using namespace std; 6 | vii mul; 7 | 8 | int main() { 9 | int n,m,q = 10; 10 | n = 10; m = 10; 11 | for(int i=1; i<=n; i++) { 12 | for(int j=1; j<=m; j++) { 13 | printf("%4d", i*j); 14 | mul.pb(i*j); 15 | } 16 | cout << endl; 17 | } 18 | sort(mul.begin(), mul.end()); 19 | 20 | while(true) { 21 | int k; 22 | scanf("%d", &k); 23 | if(!k) return 0; 24 | cout << mul[k-1] << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/iii.md: -------------------------------------------------------------------------------- 1 | All these codes were bulk uploaded, which is also many days later after actually writing them. So, I couldn't test them before uploading. As a result, there are few codes which are incomplete or gives a wrong solution. Please test the codes at first by submitting them in OJ before using them.
2 | In practice, there are codes which I wrote to practice data structures and algorithms. There might be few incomplete/WA giving solutions.
3 | In contest, there are codes of the contests which I actually participated. So, there are a lot of codes which I couldn't complete or gave Wrong Answer verdict.
4 | -------------------------------------------------------------------------------- /HDU/2993 brute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,k, a[10010], s[10010]; 6 | 7 | int main() { 8 | scanf("%d %d", &n, &k); 9 | for(int i=1; i<=n; i++) scanf("%d", &a[i]); 10 | for(int i=1; i<=n; i++) s[i] = s[i-1] + a[i]; 11 | 12 | double ans = 0; 13 | int p,q; 14 | for(int i=0; i<=n; i++) { 15 | for(int j=i+k; j<=n; j++) { 16 | double temp = 1.0 * (s[j]-s[i]) / (j-i); 17 | if(temp > ans) { 18 | ans = temp; 19 | p = i; q = j; 20 | } 21 | } 22 | } 23 | cout << p << ' ' << q << ' ' << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /HDU/Robotic Sort.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LightOJ/1000.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T, i, a, b; 6 | 7 | scanf("%d", &T); 8 | 9 | for(i=1; i<=T; i++) 10 | { 11 | scanf("%d %d", &a, &b); 12 | printf("Case %d: %d\n", i, a+b); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /LightOJ/1001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t, n; 6 | scanf("%d", &t); 7 | while(t) 8 | { 9 | scanf("%d", &n); 10 | if(n>=10) printf("%d %d\n", n-10, 10); 11 | else printf("%d %d\n", 0, n); 12 | t--; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LightOJ/1005- rooks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long long int choose(long long int n,long long int r,long long int k) 4 | { 5 | long long int c=1; 6 | while(r<=k) 7 | { 8 | c=c * n/r*n; 9 | n--; r++; 10 | 11 | } 12 | return c; 13 | } 14 | 15 | int main() 16 | { 17 | long long int t,T, n,k; 18 | scanf("%lld", &T); 19 | for(t=1; t<=T; t++) 20 | { 21 | scanf("%lld %lld", &n, &k); 22 | if(k>n) printf("Case %d: 0\n", t); 23 | else printf("Case %lld: %lld\n",t, choose(n,1,k)); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LightOJ/1008 - Fibsieve`s Fantabulous Birthday.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int t,T; 6 | long long int s, root, c, ctime; 7 | scanf("%d", &T); 8 | for(t=1; t<=T; t++) 9 | { 10 | scanf("%lld", &s); 11 | root=sqrt(s-1); 12 | 13 | c=ceil(sqrt(s)); 14 | ctime= c*c - c + 1; 15 | if(root%2) 16 | { 17 | if(sctime) printf("Case %d: %lld %lld\n",t, c-s+ctime, c); 23 | else printf("Case %d: %lld %lld\n",t, c, c-ctime+s); 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LightOJ/1011 - Marriage Ceremonies.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int mat[17][17], n; 4 | 5 | int maxcomb() 6 | { 7 | int i, sum=0; 8 | int flag[17]; 9 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int t,T, n,i,a, total; 6 | scanf("%d", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | total=0; 10 | scanf("%d", &n); 11 | while(n--) 12 | { 13 | scanf("%d", &a); 14 | if(a>0) total+=a; 15 | } 16 | printf("Case %d: %d\n", t,total); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /LightOJ/1020 - A Childhood Game.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, n; 6 | char name[10]; 7 | scanf("%d", &T); 8 | for(t=1;t<=T; t++) 9 | { 10 | scanf("%d %s", &n, name); 11 | getchar(); 12 | if(name[0]=='A') 13 | { 14 | if(!((n-1)%3)) printf("Case %d: Bob\n", t); 15 | else printf("Case %d: Alice\n", t); 16 | } 17 | else 18 | { 19 | if(!(n%3)) printf("Case %d: Alice\n", t); 20 | else printf("Case %d: Bob\n", t); 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /LightOJ/1021 - Painful Bases.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int b,k, sz; 6 | string digits; 7 | 8 | int getRes(int mask) { 9 | 10 | if(mask == (1<> T; 20 | for(int t=1; t<=T; t++) { 21 | 22 | //int b,k; 23 | cin >> b >> k; 24 | string digits; 25 | sz = digits.size(); 26 | //cin >> digits; 27 | 28 | getRes(0); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /LightOJ/1022 - Circle in Square.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double con = 4 - 2*acos(0.0) ; 5 | 6 | int main() 7 | { 8 | int t,T; 9 | double r; 10 | scanf("%d", &T); 11 | for(t=1; t<=T; t++) 12 | { 13 | scanf("%lf", &r); 14 | printf("Case %d: %.2lf\n", t, r*r*con); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /LightOJ/1023 - Discovering Permutations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int n,k; 4 | char str[28]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 5 | 6 | void permute(int a) 7 | { 8 | 9 | } 10 | 11 | int main() 12 | { 13 | int t,T; 14 | scanf("%d", &T); 15 | for(t=1; t<=T; t++) 16 | { 17 | scanf("%d %d", &n, &k); 18 | permute(0); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /LightOJ/1031 - Easy Game.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, n, ara[102], i,j, max1,max2, temp=0, sum=0, dif; 6 | scanf("%d", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | max1=0; max2=0; temp=0; sum=0; dif=0; 10 | scanf("%d", &n); 11 | scanf("%d", &ara[0]); max1=ara[0]; 12 | for(i=1; iara[n] && ara[i]-ara[n]>dif) dif=abs(ara[i]-ara[n]); 19 | 20 | //if(max1==ara[n-1]) printf("Case %d: %d\n", t,max1); 21 | printf("Case %d: %d\n", t, dif); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /LightOJ/1031 - Easy Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int nums[111]; 6 | int lSum, rSum, dif; 7 | 8 | int maxDif(int st, int ed, int player) { 9 | 10 | int sumLeft = 0; 11 | for(int i=st; i<=ed; i++) { 12 | sumLeft += nums[i]; 13 | } 14 | } 15 | 16 | int main() { 17 | 18 | int t,T; 19 | scanf("%d", &T); 20 | for(t=1; t<=T; t++) { 21 | 22 | int n; 23 | scanf("%d", &n); 24 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | char str[103]; 6 | int dp[103][103]; 7 | 8 | int getMin(int st, int ed) { 9 | if(st >= ed) return 0; 10 | if(dp[st][ed] != -1) return dp[st][ed]; 11 | 12 | if(str[st] == str[ed]) return dp[st][ed] = getMin(st+1, ed-1); 13 | else return dp[st][ed] = 1 + min(getMin(st+1, ed), getMin(st, ed-1)); 14 | } 15 | 16 | int main() { 17 | int t,T; 18 | scanf("%d", &T); 19 | for(t=1; t<=T; t++) { 20 | memset(dp, -1, sizeof(dp)); 21 | scanf("%s", str); 22 | 23 | printf("Case %d: %d\n", t, getMin(0, strlen(str)-1)); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /LightOJ/1043 - Triangle Partitioning.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | double AB,BC,CA, rat; 11 | cin >> AB >> BC >> CA >> rat; 12 | 13 | printf("Case %d: %.10lf\n", t, AB * sqrt(rat/(rat+1)) ); 14 | } 15 | 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /LightOJ/1045 - Digits of Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double ans[1000005]; 5 | 6 | int main() 7 | { 8 | int t,T, n,b, x; 9 | scanf("%d", &T); 10 | for(x=1; x<1000002; x++) ans[x]=log(x)+ans[x-1]; 11 | 12 | 13 | for(t=1; t<=T; t++) 14 | { 15 | scanf("%d %d", &n,&b); 16 | if(n==0 || n==1) printf("Case %d: %d\n", t,1); 17 | else printf("Case %d: %d\n", t,(int) ceil(ans[n]/log(b))); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /LightOJ/1053 - Higher Math.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, a,b,c; 6 | scanf("%d", &T); 7 | for(t=1;t<=T; t++) 8 | { 9 | scanf("%d %d %d", &a,&b,&c); 10 | a*=a; b*=b; c*=c; 11 | if(a==b+c || a==abs(b-c)) printf("Case %d: yes\n", t); 12 | else printf("Case %d: no\n", t); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LightOJ/1056 - Olympics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define pb push_back 4 | #define LIM 10000000 5 | #define MOD 1000000007 6 | #define MAX 10000000 7 | #define pi acos(-1) 8 | 9 | using namespace std; 10 | 11 | int main() { 12 | 13 | int T; 14 | scanf("%d", &T); 15 | for(int t=1; t<=T; t++) { 16 | int a,b; 17 | scanf("%d : %d", &a, &b); 18 | double g = 1.0*a/b; 19 | double theta = pi - 2*atan(g); 20 | double w = 200 / (g + theta/2*sqrt(1+g*g)); 21 | printf("Case %d: %.10lf %.10lf\n",t, g*w, w); 22 | } 23 | return 0; 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /LightOJ/1069 - Lift.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, i, e; 6 | scanf("%d", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | scanf("%d %d", &i, &e); 10 | printf("Case %d: %d\n", t, 19 + 4*(i + abs(i-e))); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /LightOJ/1072 - Calm Down.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double R,n; 7 | int i,t; 8 | scanf("%d",&t); 9 | for(i=1; i<=t; i++) 10 | { 11 | scanf("%lf%lf",&R,&n); 12 | double ans=(R*sin(acos(-1.0)/n)/(sin(acos(-1.0)/n)+1)); 13 | printf("Case %d: %lf\n",i,ans); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /LightOJ/1077 - How Many Points .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | // cout << __gcd(0,0) << endl; 9 | 10 | int T; 11 | scanf("%d", &T); 12 | for(int t=1; t<=T; t++) { 13 | 14 | ll a,b,c,d; 15 | scanf("%lld %lld %lld %lld", &a,&b,&c,&d); 16 | // cout << abs(a-c) 17 | printf("Case %d: %lld\n", t, __gcd( abs(a-c) , abs(b-d) ) + 1 ); 18 | } 19 | 20 | return 0; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /LightOJ/1078 - Integer Divisibility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n,d, c,x, cnt = 1, total; 12 | scanf("%d %d", &n,&d); 13 | x = d % n; 14 | c = 10 % n; 15 | total = x; 16 | while(total % n != 0) { 17 | // cout << x << endl; 18 | // getchar(); 19 | cnt++; 20 | x = (c*x)%n ; 21 | total = (total+x) % n; 22 | } 23 | printf("Case %d: %d\n", t, cnt); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LightOJ/1095 - Arrange the Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define MOD 1000000007 4 | 5 | using namespace std; 6 | 7 | int n,m,k; 8 | int strict, left, taken[1010]; 9 | 10 | int combination(int indx) { 11 | 12 | int ans = 0; 13 | for(int i=1; i<=left; i++) { 14 | if(!taken[i]) { 15 | taken[i] = 1; 16 | ans += combination(indx+1); 17 | taken[i] = 0; 18 | } 19 | } 20 | } 21 | 22 | int main() { 23 | 24 | int T; 25 | scanf("%d", &T); 26 | for(int t=1; t<=T; t++) { 27 | 28 | scanf("%d %d %d", &n,&m,&k); 29 | 30 | strict = m-k; left = n-k; 31 | memset(taken, 0, sizeof(taken)); 32 | 33 | printf("%lld\n", combination(0)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LightOJ/1098 - A New Function.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n; 7 | 8 | int main() { 9 | 10 | int T; 11 | scanf("%d", &T); 12 | for(int t=1; t<=T; t++) { 13 | 14 | ll ans = 0, pre; 15 | scanf("%lld", &n); 16 | 17 | ans = 0; 18 | pre = n; 19 | 20 | ll sq = sqrt(n); 21 | for(ll i=2; i<=sq; i++) { 22 | ll div = n / i; 23 | 24 | ans += (i-2)*( pre*(pre+1)/2 - div*(div+1)/2 ); 25 | ans += (div-1)*i; 26 | 27 | pre = div; 28 | } 29 | 30 | if(pre != sq) { 31 | ans += (sq-1)*( pre*(pre+1)/2 - sq*(sq+1)/2 ); 32 | } 33 | 34 | printf("Case %d: %lld\n", t, ans); 35 | } 36 | 37 | return 0; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /LightOJ/1107 - How Cow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, n, x1,y1,x2,y2, x,y; 6 | scanf("%d", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | scanf("%d %d %d %d", &x1,&y1,&x2,&y2); 10 | scanf("%d", &n); 11 | 12 | printf("Case %d:\n", t); 13 | 14 | while(n--) 15 | { 16 | scanf("%d %d", &x,&y); 17 | if(x1 2 | 3 | int sv[33]; 4 | 5 | svgen() 6 | { 7 | int i, j; 8 | for(i=2; i<8; i++) if(!sv[i]) for(j=i*i; j<34; j+=i) sv[j]=1; 9 | } 10 | 11 | int main() 12 | { 13 | int n, i,j, c, div, term, ara[1005]; 14 | svgen(); 15 | for(n=2; n<1001; n++) 16 | { 17 | div=1; 18 | term=n; 19 | for(i=2; i<33 && term>1; i++) if(!sv[i] && n%i==0) 20 | { 21 | c=0; 22 | while(term%i==0) 23 | { 24 | c++; 25 | term/i; 26 | } 27 | div*=(c+1); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /LightOJ/1113 - Discover the Web.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,T, i,j, lim, cur, str[100000][100]; 6 | scanf("%d", &T); 7 | getchar(); 8 | for(t=1; t<=T; t++) 9 | { 10 | while(gets) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LightOJ/1116 - Ekka Dokka.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int t,T, w, a; 6 | scanf("%lld", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | scanf("%lld", &w); 10 | if(w%2) printf("Case %d: Impossible\n", t); 11 | else 12 | { 13 | a=1; 14 | while(!(w%2)) 15 | { 16 | w/=2; 17 | a*=2; 18 | } 19 | printf("Case %lld: %lld %lld\n",t, w, a); 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /LightOJ/1136 - Division by 3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int t,T, a,b; 6 | scanf("%lld", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | scanf("%lld %lld", &a, &b); 10 | a--; 11 | 12 | printf("Case %lld: %lld\n",t, (b*2)/3 - (a*2)/3); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LightOJ/1148 - Mad Counting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n,x,ans=0, flag[1000006] = {0}; 12 | scanf("%d", &n); 13 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | ll dif; 12 | scanf("%lld", &dif); 13 | 14 | ll amid = dif/9 * 10; 15 | 16 | ll lo = max(0LL, amid - 50 ), hi = amid + 50; 17 | 18 | printf("Case %d:", t); 19 | while(lo <= hi) { 20 | 21 | if(lo - lo/10 == dif) printf(" %lld", lo); 22 | lo++; 23 | } 24 | printf("\n"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LightOJ/1178 - Trapezium.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | 11 | double a,b,c,d, x, s, atr, h; 12 | scanf("%lf %lf %lf %lf", &a,&b,&c,&d); 13 | if(c > a) { 14 | double tmp = c; 15 | c = a; 16 | a = tmp; 17 | } 18 | 19 | x = a - c; 20 | s = (x+b+d) / 2.0; 21 | atr = sqrt(s * (s-x) * (s-b) * (s-d)); 22 | h = 2*atr / x; 23 | 24 | printf("Case %d: %.10lf\n", t, 0.5*(a+c)*h ); 25 | 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /LightOJ/1179 - Josephus Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | ll n,k; 12 | scanf("%lld %lld", &n,&k); 13 | 14 | ll res = 1; 15 | for(ll i=2; i<=n; i++) res = (res+k-1) % i + 1; 16 | 17 | printf("Case %d: %lld\n", t, res); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /LightOJ/1182 - Parity.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int t,T, n, sum; 6 | scanf("%lld", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | sum=0; 10 | scanf("%lld", &n); 11 | while(n) 12 | { 13 | if(n%2) sum++; 14 | n/=2; 15 | } 16 | if(sum%2) printf("Case %lld: odd\n",t); 17 | else printf("Case %lld: even\n", t); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /LightOJ/1186 - Incredible Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | cin >> T; 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n, wht[110], b , xorSum = 0; 12 | scanf("%d", &n); 13 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | cin >> T; 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n, a,b, xorSum = 0; 12 | // int moves[200]; 13 | scanf("%d", &n); 14 | // scanf("%d", &a); 15 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int t,T, r1,c1,r2,c2, x,y, m1,m2,m3,m4; 6 | scanf("%d", &T); 7 | for(t=1; t<=T; t++) 8 | { 9 | scanf("%d %d %d %d", &r1,&c1,&r2,&c2); 10 | m1=r1%2; m2=c1%2; m3=r2%2; m4=c2%2; 11 | if( (m1==m3 && m2==m4) || (m1!=m3 && m2!=m4) ) 12 | { 13 | x=abs(c1-c2); 14 | y=abs(r1-r2); 15 | if(x==y) printf("Case %d: 1\n", t); 16 | else printf("Case %d: 2\n", t); 17 | } 18 | else printf("Case %d: impossible\n", t); 19 | 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /LightOJ/1213 - Fantasy of a Summation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n,k,mod, total = 0, c; 7 | 8 | ll power(ll n, ll r) { 9 | if(!n) return 0; 10 | if(!r) return 1; 11 | if(r%2) return (power(n, r-1) * n) % mod; 12 | ll ans = power(n, r/2); 13 | return (ans*ans) % mod; 14 | } 15 | 16 | int main() { 17 | 18 | int T; 19 | scanf("%d", &T); 20 | for(int t=1; t<=T; t++) { 21 | total = 0; 22 | scanf("%d %d %d", &n,&k,&mod); 23 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | 12 | string a; 13 | ll b, sz; 14 | ll c = 0; 15 | 16 | cin >> a; sz = a.size(); 17 | scanf("%lld", &b); 18 | 19 | b = abs(b); 20 | int i = 0; if(a[i] == '-') i++; 21 | 22 | for(; i 2 | #define ll long long int 3 | #define pb push_back 4 | #define LIM 10000000 5 | #define MOD 1000000007 6 | #define MAX 10000000 7 | #define pi acos(-1) 8 | 9 | using namespace std; 10 | 11 | int main() { 12 | 13 | int T; 14 | scanf("%d", &T); 15 | for(int t=1; t<=T; t++) { 16 | int R,r, H, p ; 17 | double Hy, Rx; 18 | scanf("%d %d %d %d", &R, &r, &H, &p); 19 | Hy = 1.0*H*r/(R-r); 20 | Rx = 1.0*r*(1.0 + 1.0*p/Hy) ; 21 | 22 | printf("Case %d: %.10lf\n", t, pi* (Rx*Rx*(Hy+p) - r*r*Hy) /3.0 ); 23 | } 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /LightOJ/1227 - Boiled Eggs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | //freopen("output.txt","w",stdout); 7 | int test; 8 | 9 | cin>>test; 10 | 11 | for(int t=1; t<=test; t++) { 12 | int n,p,q; 13 | 14 | cin>>n>>p>>q; 15 | int arr[n+10]; 16 | memset(arr, 0, sizeof(arr)); 17 | for(int i=0; i>arr[i]; 19 | } 20 | int cont=0; 21 | int sum=0; 22 | for(int i=0; iq) 24 | break; 25 | sum=sum+arr[i]; 26 | 27 | 28 | cont++; 29 | } 30 | printf("Case %d: %d\n",t,cont); 31 | 32 | 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /LightOJ/1234 - Harmonic Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 1000000 3 | #define ll long long int 4 | using namespace std; 5 | 6 | double harm[LIM+10]; 7 | double gama = 0.5772156649; 8 | 9 | int main() { 10 | 11 | harm[1] = 1; 12 | for(ll i=2; i<=LIM; i++) harm[i] = harm[i-1] + 1.0 / i ; 13 | 14 | // for(int i=1; i<=20; i++) cout << harm[i] << " : " << log(i) + gama << endl; 15 | 16 | int T; 17 | scanf("%d", &T); 18 | for(int t=1; t<=T; t++) { 19 | 20 | ll n; 21 | scanf("%lld", &n); 22 | if(n <= LIM) printf("Case %d: %.10lf\n", t, harm[n]); 23 | else printf("Case %d: %.10lf\n", t, log(n) + gama + 1.0/(2*n) - 1.0/(12*n*n) ); 24 | } 25 | 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /LightOJ/1241 - Pinocchio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T; t++) { 9 | int n, a,b, ans = 0; 10 | scanf("%d", &n); 11 | scanf("%d", &a); 12 | if(a <= 2) ans = 0; 13 | else ans = (a-2 + 4) / 5; 14 | for(int i=1; i a) ans += (b-a + 4) / 5; 17 | a = b; 18 | } 19 | printf("Case %d: %d\n", t, ans); 20 | } 21 | return 0; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /LightOJ/1247 - Matrix Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | cin >> T; 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n,m; 12 | scanf("%d %d", &m, &n); 13 | 14 | int cell, rows, xorSum = 0; 15 | // memset(rows, 0, sizeof(rows)); 16 | 17 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | double ex[100005]; 6 | 7 | int main() { 8 | 9 | int T; 10 | scanf("%d", &T); 11 | for(int t=1; t<=T; t++) { 12 | 13 | int all; 14 | scanf("%d", &all); 15 | ex[0] = 0; 16 | 17 | for(int rem = 1; rem<=all; rem++) { 18 | ex[rem] = ex[rem-1] + 1.0*all/rem; 19 | } 20 | 21 | printf("Case %d: %.10lf\n", t, ex[all]); 22 | } 23 | 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /LightOJ/1253 - Misere Nim.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | cin >> T; 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n, a, sum = 0, xorSum = 0; 12 | scanf("%d", &n); 13 | for(int i=0; i 2 | #define MXV 5 3 | #define MXX 100 4 | using namespace std; 5 | 6 | int main() { 7 | srand(time(NULL)); 8 | freopen("1262i.txt", "w", stdout); 9 | 10 | int T = 20; 11 | cout << T << endl << endl; 12 | while(T--) { 13 | int n = rand()%MXV+1, m = rand()%MXV+1; 14 | int grid[MXV][MXV]; 15 | cout << n << ' ' << m << endl; 16 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int t,d; 6 | 7 | int main() { 8 | 9 | 10 | int T; 11 | scanf("%d", &T); 12 | for(int tt=1; tt<=T; tt++) { 13 | scanf("%d %d", &t, &d); 14 | if(t%2) printf("Case %d: %.10lf\n", tt, 0.0); 15 | else printf("Case %d: %.10lf\n", tt, 1.0 / (t+1) ); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /LightOJ/1272 brute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int ans; 6 | int n,ara[110]; 7 | 8 | void f(int in, int v) { 9 | if(in == n) { 10 | ans = max(ans, v); 11 | return; 12 | } 13 | f(in+1, v^ara[in]); 14 | f(in+1, v); 15 | } 16 | 17 | int main() { 18 | scanf("%d", &n); 19 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | 12 | ll n,c, x, xx; 13 | scanf("%lld %lld", &n,&c); 14 | 15 | if(!n) x = 0; 16 | else x = c / (2*n); 17 | xx = x+1; 18 | 19 | if(!n) printf("Case %d: 0\n", t); 20 | else if( x*(c-x*n) >= xx*(c-xx*n) ) printf("Case %d: %lld\n", t, x); 21 | else printf("Case %d: %lld\n",t, xx); 22 | } 23 | 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /LightOJ/1294 - Positive Negative Sign.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | 12 | ll n,m; 13 | scanf("%lld %lld", &n,&m); 14 | printf("Case %d: %lld\n",t, ( n/(2*m) ) * m*m ); 15 | 16 | } 17 | 18 | return 0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /LightOJ/1297 - Largest Box.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | 11 | double A,B,C; 12 | double l,w; 13 | scanf("%lf %lf", &l,&w); 14 | A = 12, B = -4*(l+w), C = l*w; 15 | 16 | double x1 = ( -B + sqrt(B*B - 4*A*C) ) / (2*A) ; if(x1 <= 0) x1 = 0; 17 | double x2 = ( -B - sqrt(B*B - 4*A*C) ) / (2*A) ; if(x2 <= 0) x2 = 0; 18 | 19 | // cout << A << ' ' << B << ' ' << C << endl; 20 | // cout << x1 << ' ' << x2 << endl; 21 | 22 | printf("Case %d: %.10lf\n", t, max( ( (l-2*x1)*(w-2*x1)*x1) , ( (l-2*x2)*(w-2*x2)*x2) ) ); 23 | 24 | 25 | } 26 | 27 | return 0; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /LightOJ/1303 - Ferris Wheel CHEAT.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LightOJ/1304 rand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 7 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | srand(time(NULL)); 8 | freopen("1304i.txt", "w", stdout); 9 | 10 | int T = 20; 11 | cout << T << endl; 12 | while(T--) { 13 | cout << endl; 14 | 15 | int n = rand() % LIM + 1; 16 | int m = rand() % LIM + 1; 17 | cout << m << ' ' << n << endl; 18 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | int ax,ay, bx,by, cx,cy, dx,dy, difx,dify; 11 | scanf("%d %d %d %d %d %d", &ax,&ay,&bx,&by,&cx,&cy); 12 | difx = ax - bx; 13 | dify = ay - by; 14 | dx = cx + difx; 15 | dy = cy + dify; 16 | printf("Case %d: %d %d %d\n",t, dx,dy, abs( (ax-bx)*(by-cy) - (bx-cx)*(ay-by) ) ); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /LightOJ/1307 - Counting Triangles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | int n, ara[2020]; 11 | scanf("%d", &n); 12 | for(int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | //freopen("in.txt", "r", stdin); 8 | 9 | int T; 10 | scanf("%d", &T); 11 | 12 | for(int tc = 1; tc <= T; ++tc) { 13 | double v1, v2, v3, a1, a2; 14 | scanf("%lf %lf %lf %lf %lf", &v1, &v2, &v3, &a1, &a2); 15 | 16 | double t1 = v1 / a1; 17 | double t2 = v2 / a2; 18 | double s1 = v1 * t1 - 0.5 * a1 * t1 * t1; 19 | double s2 = v2 * t2 - 0.5 * a2 * t2 * t2; 20 | 21 | printf("Case %d: %.8f %.8f\n", tc, s1 + s2, v3 * max(t1, t2)); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /LightOJ/1322 - Worst Case Trie.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ui unsigned int 3 | #define ll long long int 4 | 5 | using namespace std; 6 | 7 | int perm[10010]; 8 | 9 | int main() { 10 | 11 | perm[0] = 1; 12 | for(int i=1; i<10000; i++) perm[i] = (1 + i*perm[i-1]) % 10000; 13 | 14 | int T, n; 15 | scanf("%d", &T); 16 | for(int t=1; t<=T; t++) { 17 | scanf("%d", &n); 18 | int ans = perm[n%10000]; 19 | if(n <= 5) printf("Case %d: %d\n", t, ans); 20 | else printf("Case %d: %04d\n", t, ans); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /LightOJ/1327 random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | freopen("1327i.txt", "w", stdout); 7 | 8 | int T = 10; 9 | cout << T << endl << endl; 10 | for(int t=1; t<=T; t++) { 11 | int n = rand() % 15 + 1; 12 | cout << n << endl; 13 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n; 7 | 8 | int main() { 9 | 10 | int T; 11 | scanf("%d", &T); 12 | for(int t=1; t<=T; t++) { 13 | scanf("%lld", &n); 14 | printf("Case %d: %lld\n", t, n - (ll) sqrt(1.0*n) - (ll) sqrt(n/2.0)); 15 | } 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /LightOJ/1354 - IP Checking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int get(char ch[]) { 6 | 7 | int ans = 0; 8 | for(int i=0; i<8; i++) ans = ans*2 + (ch[i] - '0'); 9 | return ans; 10 | } 11 | 12 | int main() { 13 | 14 | int T; 15 | scanf("%d", &T); 16 | for(int t=1; t<=T; t++) { 17 | 18 | int a,b,c,d; 19 | char p[9],q[9],r[9],s[9]; 20 | scanf("%d.%d.%d.%d", &a,&b,&c,&d); 21 | scanf("%8s.%8s.%8s.%8s", p,q,r,s); 22 | 23 | int w = get(p) , x = get(q) , y = get(r) , z = get(s) ; 24 | if(a == w && b == x && c == y && d == z) printf("Case %d: Yes\n", t); 25 | else printf("Case %d: No\n", t); 26 | 27 | // printf("%s\n", p); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /LightOJ/1385 - Kingdom Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T; t++) { 9 | double a,b,c, p,q; 10 | scanf("%lf %lf %lf", &a,&b,&c); 11 | 12 | 13 | 14 | p = a*c/b; 15 | q = (a+p)*(c+p)/(b-p); 16 | 17 | if(p < 0 || b-p <= 0) printf("Case %d: -1\n", t); 18 | else printf("Case %d: %.8f\n", t, p+q); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LightOJ/1387 - Setu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T ;t++) { 10 | int n; 11 | string cmd; 12 | int am, tot = 0; 13 | 14 | scanf("%d", &n); 15 | printf("Case %d:\n", t); 16 | while(n--) { 17 | cin >> cmd; 18 | 19 | if(cmd == "donate") { 20 | scanf("%d", &am); 21 | tot += am; 22 | } 23 | else { 24 | printf("%d\n", tot); 25 | } 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /LightOJ/1389 - Scarecrow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int T; 8 | scanf("%d", &T); 9 | for(int t=1; t<=T; t++) { 10 | 11 | int n, cnt=0; 12 | string fld; 13 | scanf("%d", &n); 14 | cin >> fld; 15 | fld += "##"; 16 | 17 | 18 | for(int i=0; i 2 | #define LIM 10 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | srand(time(NULL)); 8 | freopen("1390i.txt", "w", stdout); 9 | 10 | int T = 20; 11 | cout << T << endl; 12 | while(T--) { 13 | cout << endl; 14 | 15 | int n = rand() % LIM + 1; 16 | int m = rand() % LIM + 1; 17 | cout << m << ' ' << n << endl; 18 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int T; 9 | cin >> T; 10 | for(int t=1; t<=T; t++) { 11 | 12 | int r,c, grid, xorSum = 0; 13 | scanf("%d %d", &r,&c); 14 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | cout << "SDSD" << endl; 7 | } 8 | -------------------------------------------------------------------------------- /POJ/2411 Mondriaan's Dream.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /SPOJ/LOOPEXP - Loop Expectation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | double f[100005]; 6 | 7 | int main() { 8 | f[1] = 1; 9 | for(int i=2; i<=100000; i++) f[i] = 1.0/i + f[i-1]; 10 | int t; 11 | scanf("%d", &t); 12 | while(t--) { 13 | int n; 14 | scanf("%d", &n); 15 | printf("%.8f\n", f[n]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SPOJ/QWERTY04 - TRIVIADOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | while(T--) { 9 | int n; 10 | scanf("%d", &n); 11 | string s; 12 | cin >> s; 13 | int in = 0, a=0, b=0; 14 | while(in < s.size()) { 15 | if(s[in] == 'X') { 16 | a++; 17 | while(in= b) printf("X\n"); 25 | else printf("O\n"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SPOJ/TRICENTR - Triangle From Centroid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | scanf("%d", &t); 8 | while(t--) { 9 | double a,b,c, oa,ob,oc, s, area, R, GH; 10 | scanf("%lf %lf %lf %lf", &a, &oa,&ob,&oc); 11 | b = a*oa/ob; 12 | c = a*oa/oc; 13 | 14 | s = (a+b+c)/2.0; 15 | area = sqrt( s*(s-a)*(s-b)*(s-c) ); 16 | 17 | R = a*b*c / (4*area); 18 | GH = 2 * sqrt( R*R - (a*a+b*b+c*c)/9.0 ); 19 | 20 | printf("%.3f %.3f\n", area, GH); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SPOJ/loop.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /SPOJ/randomd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 1 3 | #define MAX 1000000 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | srand(time(NULL)); 9 | 10 | freopen("aqi.txt", "w", stdout); 11 | 12 | int n = LIM; 13 | cout << n << endl; 14 | 15 | for(int i=0; i 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n; 7 | ll dp[305][505]; 8 | 9 | ll getMax( ll brick, ll now) { 10 | 11 | if(!brick) return 1; 12 | if(brick < 0) return 0; 13 | 14 | if(dp[brick][now] == -1) { 15 | ll temp = 0; 16 | for(ll i = now; i <= brick; i++) { 17 | printf("brick: %lld, i %lld\n", brick, i); 18 | temp += getMax(brick-i, i+1); 19 | printf("temp %lld\n", temp ); 20 | } 21 | dp[brick][now] = temp; 22 | } 23 | 24 | return dp[brick][now]; 25 | 26 | } 27 | 28 | int main() { 29 | cin >> n; 30 | 31 | memset(dp, -1, sizeof(dp)); 32 | 33 | printf("%lld\n", getMax(n, 1)-1); 34 | } 35 | -------------------------------------------------------------------------------- /Timus/1017 - Staircase 3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | ll n; 7 | ll dp[505][505]; 8 | 9 | ll getMax( ll brick, ll last) 10 | { 11 | 12 | if(!brick) return 1; 13 | else if(brick < 0) return 0; 14 | //else if(brick+1 == last) return 1; 15 | 16 | if(dp[brick][last] == 0) 17 | { 18 | ll temp = 0; 19 | for(ll i=last+1; i<=brick; i++) 20 | { 21 | temp += getMax(brick-i, i); 22 | } 23 | return dp[brick][last] = temp; 24 | } 25 | else return dp[brick][last]; 26 | } 27 | 28 | int main() 29 | { 30 | //cin >> n; 31 | scanf("%I64d", &n); 32 | 33 | //memset(dp, -1, sizeof(dp)); 34 | 35 | printf("%I64d\n", getMax(n, 0)-1); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /UVLive/case.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | freopen("2738i.txt", "w", stdout); 7 | for(int i=1; i<=1000; i++) cout << i << endl; 8 | cout << "#" << endl; 9 | } 10 | -------------------------------------------------------------------------------- /UVa/0.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("_____\n| |\n| |\n| |\n|___|\n"); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /UVa/00122 - Trees on the level.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct info{ 6 | int u; 7 | string seq; 8 | info() {} 9 | info(int uu, string ss) { 10 | u = uu; seq = ss; 11 | } 12 | bool operator < (const info &b) const { 13 | return seq.size() < b.seq.size() || seq < b.seq 14 | } 15 | }; 16 | 17 | int main() { 18 | while(scanf("%s", &str)) { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UVa/00136.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int count=1, n=1; 6 | 7 | while(count<=1500) 8 | { 9 | n=n+1; 10 | if(!(n%2) || !(n%3) || !(n%5)) count++; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /UVa/00374 mun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long long int bigmod (int b, int p, int m) 4 | { 5 | long long int r; 6 | 7 | if(!p) return 1; 8 | else if(p%2) 9 | { 10 | p=p-1; 11 | return (bigmod(b,p,m)*(b%m))%m; 12 | } 13 | else 14 | { 15 | p=p/2; 16 | r=bigmod(b,p,m); 17 | return ((r%m)*(r%m))%m; 18 | } 19 | } 20 | 21 | int main() 22 | { 23 | long long int b,p,m; 24 | long long int r; 25 | 26 | while((scanf("%lld %lld %lld", &b, &p, &m))==3) 27 | { 28 | 29 | 30 | printf("%lld\n", bigmod(b,p,m)); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVa/00374 muntasir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long long int bigmod ( long long a, int b, int c); 5 | int main(){ 6 | long long int b; 7 | int p,m; 8 | 9 | while(scanf("%lld %d %d",&b,&p,&m)==3) 10 | printf("%d\n",bigmod(b,p,m)); 11 | return 0; 12 | } 13 | long long int bigmod ( long long a, int b, int c){ 14 | if ( b == 0 )return 1; 15 | if ( b % 2 ) return ((a%c)*(bigmod(a,b-1,c)))%c; 16 | 17 | else { 18 | long long d = bigmod(a,b/2,c); 19 | return ((d%c)*(d%c))%c; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UVa/00374.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int b,p,m; 6 | long long int r; 7 | 8 | while((scanf("%lld %lld %lld", &b, &p, &m))==3) 9 | { 10 | 11 | r=1; 12 | while(p) 13 | { 14 | r=((r*b)%m); 15 | p--; 16 | } 17 | printf("%lld\n", r); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/00406 - Prime Cuts.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool isNotPrime[1111]; 6 | 7 | void sieve() { 8 | 9 | for(int i=4; i<1010; i+=2) { 10 | isPrime[i] = true; 11 | } 12 | 13 | for(int i=3; i<33; i++) { 14 | for(int j=i+i; j<1111; j+=i) { 15 | 16 | } 17 | } 18 | } 19 | 20 | int main() { 21 | 22 | int n,c; 23 | 24 | sieve(); 25 | 26 | while(scanf("%d %d", &n,&c)) { 27 | 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /UVa/00458 new.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char i; 7 | char ch; 8 | int len; 9 | while(scanf("%c", &ch)) ///better algo but they made the EOF in a way which work only with scanf(%s) 10 | { 11 | if(ch=='\n') putchar(ch); 12 | else putchar(ch-7); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/00458-the decoder (rank-380).c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char i; 7 | char ch[80]; 8 | char len; 9 | while(gets(ch)) 10 | { 11 | len=strlen(ch); 12 | for(i=0; i 2 | int main() 3 | { 4 | int a,f,t,i,j,k,l; 5 | scanf("%d",&t); 6 | for(i=1;i<=t;i++){ 7 | scanf("%d %d",&a,&f); 8 | for(k=1;k<=f;k++){ 9 | for(j=1;j<=a;j++){ 10 | for(l=1;l<=j;l++){ 11 | printf("%d",j); 12 | } 13 | printf("\n"); 14 | } 15 | for(j=a-1;j>=1;j--){ 16 | for(l=1;l<=j;l++){ 17 | printf("%d",j); 18 | } 19 | printf("\n"); 20 | } 21 | if(i!=t || k!=f){ 22 | printf("\n"); 23 | } 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /UVa/00488 saadmaan sakib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | 7 | double a,b,t,i,fstep,f2step; 8 | scanf("%lf",&t); 9 | while(t) 10 | { 11 | scanf("%lf%lf",&a,&b); 12 | while(b) 13 | { 14 | for(i=1; i<=a; i++) 15 | { 16 | fstep=(i/9)*((pow(10,i))-1); 17 | printf ("%0.lf\n",fstep); 18 | } 19 | 20 | i=i-2; 21 | for(i; i>0; i--) 22 | { 23 | f2step=(i/9)*((pow(10,i))-1); 24 | printf ("%0.lf\n",f2step); 25 | } 26 | b--; 27 | if(b || t>1) printf("\n"); 28 | } 29 | t--; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVa/00494.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str[1000]; 7 | int i; 8 | 9 | while(gets(str)) 10 | { 11 | int count=0; 12 | for(i=0; i='a' && str[i]<='z') || (str[i]>='A' &&str[i]<='Z')) && !((str[i+1]>='a' && str[i+1]<='z') || (str[i+1]>='A' && str[i+1]<='Z'))) 15 | count++; 16 | } 17 | 18 | printf("%d\n", count); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /UVa/00495.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | 7 | while(scanf("%d", &n)!=EOF) 8 | { 9 | 10 | unsigned long long int s=0, i=-1, j=1, k=0; 11 | while(s<=n) 12 | { 13 | k=i+j; 14 | i=j; 15 | j=k; 16 | s++; 17 | } 18 | printf("%lld\n", k); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /UVa/00523 - Minimum Transport Cost.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int t; 8 | int graph[1000][1000]; 9 | cin >> t; 10 | 11 | while(t--) { 12 | 13 | memset(graph, 0, sizeof(graph)); 14 | 15 | int i=1; 16 | char c; 17 | while(scanf("%c", &c) && c != '\n') { 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UVa/00530.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int comb(int n, int k) 4 | { 5 | int i; 6 | double comb=1.0; 7 | if(k==0 || n==k) return 1; 8 | for (i = 1; i <= k; i++) 9 | { 10 | comb*= (n - k + i); 11 | comb/=i; 12 | } 13 | return comb; 14 | } 15 | 16 | int main() 17 | { 18 | int n,k,k1; 19 | while((scanf("%d %d", &n, &k))==2) 20 | { 21 | if(!n && !k) break; 22 | 23 | k1=n-k; 24 | if(k1 2 | 3 | int main() 4 | { 5 | double h,h2,u,d,f; 6 | int a; 7 | while(scanf("%lf %lf %lf %lf", &h, &u, &d, &f)) 8 | { 9 | if(!h) return 0; 10 | a=0; 11 | h2=0; 12 | f=u*f/100; 13 | while(h2<=h) 14 | { 15 | 16 | a++; 17 | u-=f; 18 | } 19 | if(h<0) printf("success on day %d\n", a); 20 | else printf("failure on day %d\n", a); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /UVa/00579.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int h, m; 6 | float ang; 7 | 8 | while(1) 9 | { 10 | scanf("%d:%d", &h,&m); 11 | if(!h && !m) break; 12 | ang=(30.0*h-5.5*m); 13 | 14 | if(ang<0) ang=-1*ang; 15 | 16 | if(ang>180.0) printf("%0.3f\n", 360-ang); 17 | else printf("%0.3f\n", ang); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/00591.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, i=1, j, b, hos[50], count; 6 | 7 | while(1) 8 | { 9 | scanf("%d", &n); 10 | if(n==0) break; 11 | 12 | b=0; 13 | count=0; 14 | for(j=0; jb) count=count+hos[j]-b; 21 | 22 | printf("Set #%d\n", i); 23 | printf("The minimum number of moves is %d.\n", count); 24 | printf("\n"); 25 | 26 | i++; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /UVa/00674 - coin change.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int cent[] = {50, 25, 10, 5, 1}; 6 | int dp[10][10000]; 7 | 8 | int getMax(int i, int n) { 9 | 10 | if(i == 5) { 11 | if(!n) return 1; 12 | else return 0; 13 | } 14 | 15 | if(dp[i][n] != -1) return dp[i][n]; 16 | else { 17 | int c1, c2; 18 | if(n-cent[i] >= 0) 19 | c1 = getMax(i, n-cent[i]); 20 | else c1 = 0; 21 | c2 = getMax(i+1, n); 22 | 23 | return dp[i][n] = c1 + c2; 24 | 25 | 26 | } 27 | 28 | 29 | } 30 | 31 | int main() { 32 | 33 | int n; 34 | 35 | memset(dp, -1, sizeof(dp)); 36 | 37 | while(scanf("%d", &n) != EOF) { 38 | 39 | printf("%d\n", getMax(0, n)); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /UVa/00679 - Dropping Balls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n, d; 6 | 7 | int f(int level, int in, int rem) { 8 | if(level == d) return in; 9 | if(rem&1) return f(level+1, 2*in, (rem+1)/2); 10 | else return f(level+1, 2*in+1, rem/2); 11 | } 12 | 13 | int main() { 14 | int T; 15 | scanf("%d", &T); 16 | while(T--) { 17 | scanf("%d %d", &d, &n); 18 | printf("%d\n", f(1, 1, n) ); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /UVa/00694.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fun(int n, int l) 4 | { 5 | if(n==1) return 1; 6 | else if(n>l) return 0; 7 | else if(n%2) return 1+fun(3*n+1, l); 8 | else return 1+fun(n/2, l); 9 | } 10 | 11 | int main() 12 | { 13 | int t=1, i,j, n,l; 14 | while(1) 15 | { 16 | scanf?0"%d %d", &n, &l); 17 | if(n<0 && l<0) return 0; 18 | printf("Case %d: A = %d, limit = %d, number of terms = %d\n", t++, n,l, fun(n,l)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UVa/00696 knight.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int r,c, k,x; 6 | while(scanf("%d %d", &r, &c) && ( r || c)) 7 | { 8 | if(r==1 || c==1) printf("%d knights may be placed on a %d row %d column board.\n", r+c-1 , r,c); 9 | else if(r==2 || c==2) 10 | { 11 | x=(r+c-2)%4; 12 | if(x<=2) printf("%d knights may be placed on a %d row %d column board.\n", (r+c-2)/4*4 + 2*x , r, c); 13 | else printf("%d knights may be placed on a %d row %d column board.\n", (r+c-2)/4*4 + 4 , r, c); 14 | } 15 | else printf("%d knights may be placed on a %d row %d column board.\n", (r*c+1)/2 , r, c); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/00834.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b, temp; 6 | 7 | while(1) 8 | { 9 | scanf("%d %d", &a, &b); 10 | putchar('['); 11 | printf("%d", a/b); 12 | temp=b; 13 | b=a%b; 14 | a=temp; 15 | if(b) 16 | { 17 | putchar(';'); 18 | printf("%d", a/b); 19 | temp=b; 20 | b=a%b; 21 | a=temp; 22 | } 23 | while(b) 24 | { 25 | putchar(','); 26 | printf("%d", a/b); 27 | temp=b; 28 | b=a%b; 29 | a=temp; 30 | } 31 | putchar(']'); 32 | putchar('\n'); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /UVa/00897 random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | freopen("00897i.txt", "w", stdout); 8 | 9 | for(int i=1; i<10000; i++) cout << rand() % 9999999 + 1 << endl; 10 | cout << 0 << endl; 11 | } 12 | -------------------------------------------------------------------------------- /UVa/00990.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int gold[35]; 6 | int tim[35]; 7 | 8 | int main() 9 | { 10 | 11 | while(1) 12 | { 13 | int t,w; 14 | cin >> t >> w; 15 | //double time = 1.0*t/w; 16 | int n; 17 | cin >> n; 18 | for(int i=0; i> tim[i] >> gold[i]; 20 | tim[i] *= (3*w); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /UVa/01124.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char str[1000]; 6 | while(1) 7 | { 8 | gets(str); 9 | puts(str); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /UVa/100 riddho.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, j, n, len=1, max=0; 6 | while((scanf("%d %d", &i, &j))==2){ 7 | 8 | for(n=i; n<=j;) 9 | { 10 | do 11 | { 12 | if(n%2) n=3*n+1; 13 | else n=n/2; 14 | len++; 15 | } while(n>1); 16 | 17 | if(len>max) max=len; 18 | } 19 | printf("%d %d %d", i, j, max); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /UVa/10003 - Cutting Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,len, cut[55]; 6 | int dp[55][55]; 7 | 8 | int f(int lft, int rgt) { 9 | if(lft+1 == rgt) return 0; 10 | if(dp[lft][rgt] != -1) return dp[lft][rgt]; 11 | int ans = INT_MAX, cost = cut[rgt] - cut[lft]; 12 | for(int i=lft+1; i 2 | unsigned long num1[1000000],num2[1000000],res[1000000]; 3 | int main() 4 | { 5 | unsigned long long int i,j,block,digit,n1,n2,d; 6 | scanf("%llu",&block); 7 | for(i=0;i=10){ 17 | res[j+1]=res[j]/10; 18 | res[j]=res[j]%10; 19 | 20 | } 21 | 22 | } 23 | for(j=digit;j>=0;j--){ 24 | d=res[j]; 25 | printf("%d",d); 26 | } 27 | 28 | 29 | } 30 | 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVa/10035.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | unsigned long int a,b; 6 | while(1) 7 | { 8 | unsigned long int count=0, temp=0; 9 | scanf("%lu %lu", &a, &b); 10 | if(!a && !b) break; 11 | 12 | while(a || b) 13 | { 14 | if(a%10+b%10+temp<10) temp=0; 15 | else 16 | { 17 | count++; 18 | temp=1; 19 | } 20 | a=a/10; 21 | b=b/10; 22 | } 23 | 24 | if(!count) printf("No carry operation.\n"); 25 | else if(count==1) printf("1 carry operation.\n"); 26 | else printf("%lu carry operations.\n", count); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /UVa/1004 bicoloring.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int c[202][202]; 4 | 5 | int bic(int x, int flag) 6 | { 7 | for(i=0; i<) 8 | } 9 | 10 | int main() 11 | { 12 | int n, l, a,b, x; 13 | start: 14 | while(scanf("%d", &n) && n) 15 | { 16 | scanf("%d", &l); 17 | while(l) 18 | { 19 | scanf("%d %d", &a, &2b); 20 | c[a] b 21 | c[b][a]=1; 22 | l--; 23 | } 24 | for(x=0; x 2 | #include 3 | 4 | int main() 5 | { 6 | int t, n, i,j, temp, sum; 7 | scanf("%d", &t); 8 | 9 | while(t) 10 | { 11 | scanf("%d", &n); 12 | int r[n]; 13 | 14 | for(i=0; i 2 | #include 3 | int main() 4 | { 5 | long int a,b; 6 | 7 | while((scanf("%ld %ld", &a, &b))!=EOF) { 8 | printf("%ld\n", abs(a-b)); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /UVa/10055.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long int i, j; 6 | 7 | while((scanf("%ld %ld", &i, &j))!=EOF) 8 | { 9 | if(i>j) printf("%ld\n", i-j); 10 | else printf("%ld\n", j-i); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/10070.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int d4(char str[n]) 4 | { 5 | int i; 6 | i= (str[n-2]-'0')*10 + (str[n-1]-'0'); 7 | if(!(i%4)) return 1; 8 | return 0; 9 | } 10 | 11 | int check_leap(int n) 12 | { 13 | if(!(n%400)) return 1; 14 | if(!(n%4) && (n%100)) return 1; 15 | 16 | return 0; 17 | } 18 | 19 | int main() 20 | { 21 | int y; 22 | 23 | while((scanf("%d", &y))!=EOF) 24 | { 25 | if(check_leap(y)==1) printf("This is leap year.\n"); 26 | if(!(y%15)) printf("This is huluculu festival year.\n"); 27 | if(check_leap(y)==1 && !(y%55)) printf("This is buluculu festival year.\n"); 28 | if(!check_leap(y) && (y%15)) printf("This is an ordinary year.\n"); 29 | printf("\n"); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVa/10079.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n; 6 | while(1) 7 | { 8 | scanf("%lld", &n); 9 | if(n<0) break; 10 | printf("%lld\n", n*(n+1)/2+1); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/10110.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | unsigned int a; 7 | float b; 8 | while (scanf("%u",&a)==1) { 9 | if (a==0) break; 10 | 11 | b=sqrt(a); 12 | if (b== (int) b) printf("yes\n"); 13 | else printf("no\n"); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/10161.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, corner, root; 7 | while((scanf("%d", &n))==1) 8 | { 9 | if(n==0) break; 10 | 11 | root=ceil(sqrt(n)); 12 | corner=root*root-root+1; 13 | 14 | if(n==corner) printf("%d %d\n", root, root); 15 | else 16 | { 17 | if(root%2) 18 | { 19 | if(n>corner) printf ("%d %d\n", root+corner-n, root); 20 | else printf("%d %d\n", root, root+n-corner); 21 | } 22 | 23 | else 24 | { 25 | if(n>corner) printf("%d %d\n", root, root+corner-n); 26 | else printf("%d %d\n", root+n-corner, root); 27 | } 28 | } 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /UVa/10165 - Stone Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | 8 | int n, x, xorSum = 0; 9 | while(scanf("%d", &n) && n) { 10 | xorSum = 0; 11 | while(n--) { 12 | scanf("%d", &x); 13 | xorSum ^= x; 14 | } 15 | if(xorSum) printf("Yes\n"); 16 | else printf("No\n"); 17 | } 18 | return 0; 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /UVa/10209.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double a, a1, a2, a3; 7 | while((scanf("%lf", &a))!=EOF) 8 | { 9 | a1=a*a*(1-sqrt(3)+(acos(-1)/3)); 10 | a2=a*a*(2*sqrt(3)-4+(acos(-1)/3)); 11 | a3=a*a*(4-sqrt(3)-(2*acos(-1)/3)); 12 | printf("%.3lf %.3lf %.3lf\n", a1 , a2, a3); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/10212.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n,r, p; 6 | while((scanf("%lld %lld", &n, &r))==2) 7 | { 8 | p=1; 9 | while(r) 10 | { 11 | p=p*n; 12 | while((p%10)==0) p=p/10; 13 | if(p>10000000000) p=p%10000000000; 14 | n--; 15 | r--; 16 | } 17 | printf("%lld\n", p%10); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/10302.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n; 6 | 7 | while((scanf("%lld", &n))!=EOF) 8 | { 9 | printf("%lld\n", n*n*(n+1)*(n+1)/4); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /UVa/10323.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n, f; 6 | while((scanf("%lld", &n))!=EOF) 7 | { 8 | if(n<0) 9 | { 10 | if(((n)%2)) printf("Overflow!\n"); 11 | else printf("Underflow!\n"); 12 | } 13 | else 14 | { 15 | if(n>=8.0 && n<=13.0) 16 | { 17 | f=1; 18 | while(n) 19 | { 20 | f=f*n; 21 | n--; 22 | } 23 | printf("%lld\n", f); 24 | } 25 | else if(n<8.0) printf("Underflow!\n"); 26 | else printf("Overflow!\n"); 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /UVa/10346 akash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, k; 6 | 7 | while((scanf("%d %d", &n, &k))!=EOF) 8 | { 9 | printf("%d\n", n+ (n-1)/(k-1)); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /UVa/10346.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, k, t, r; 6 | 7 | while((scanf("%d %d", &n, &k))!=EOF) 8 | { 9 | t=0; 10 | r=0; 11 | while(n>0) 12 | { 13 | t=t+n; 14 | n=(n+r)/k; 15 | r=n%k; 16 | } 17 | printf("%d\n", t); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/10347 raida.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | double m1,m2,m3,a,area,s; 6 | while(scanf("%lf %lf %lf",&m1,&m2,&m3)==3){ 7 | s=(m1+m2+m3)/2.0; 8 | a=(s)*(s-m1)*(s-m2)*(s-m3); 9 | if(a>0){ 10 | area=(4/3.0)*sqrt(a); 11 | } 12 | else{ 13 | area=-1.0; 14 | } 15 | printf("%.3lf\n",area); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/10347.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double a,b,c; 7 | double s; 8 | 9 | while((scanf("%lf %lf %lf", &a, &b, &c))==3) 10 | { 11 | s=(a+b+c)/2.0; 12 | s=s*(s-a)*(s-b)*(s-c); 13 | if(s<=0) printf("%.3lf\n", -1.0); 14 | else printf("%.3lf\n", (4.0/3.0)*sqrt(s)); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /UVa/10368 - Euclid's Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | 7 | int main() { 8 | 9 | ll n,m, x, xorSum = 0; 10 | while(scanf("%lld %lld", &n, &m)) { 11 | xorSum = 0; 12 | if(!n && !m) return 0; 13 | if(m > n) swap(n,m); 14 | 15 | while(1) { 16 | x = n/m; 17 | if(n%m==0) { 18 | // xorSum ^= 1; 19 | break; 20 | } 21 | xorSum ^= x; 22 | x = m; 23 | m = n%m; 24 | n = x; 25 | } 26 | if(xorSum) printf("Stan wins\n"); 27 | else printf("Ollie wins\n"); 28 | } 29 | return 0; 30 | } 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /UVa/10432.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double r, n, pi=acos(-1); 7 | 8 | while((scanf("%lf %lf", &r, &n))!=EOF) 9 | { 10 | printf("%.3lf\n", n/2.0*r*r*sin(2*pi/n)); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/10469.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b; 6 | while(scanf("%d %d", &a, &b)!=EOF) printf("%d\n", a^b); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /UVa/10491 - Cows and Cars.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a,b,c; 7 | while( scanf("%d %d %d", &b,&a,&c) != EOF ) { 8 | int n = a + b; 9 | printf("%.5lf\n", 1.0*a/n*(a-1)/(n-1-c) + 1.0*b/n*a/(n-1-c) ); 10 | 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/10522.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | double ha, hb, hc, a; 8 | scanf("%d", &n); 9 | while(n) 10 | { 11 | scanf("%lf %lf %lf", &ha, &hb, &hc); 12 | a=(1/ha+1/hb+1/hc)*(1/ha+1/hb-1/hc)*(1/hb+1/hc-1/ha)*(1/hc+1/ha-1/hb); 13 | if(a<=0 || !ha || !hb || !hc) 14 | { 15 | printf("These are invalid inputs!\n"); 16 | n--; 17 | } 18 | else printf("%.3lf\n", 1/sqrt(a)); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /UVa/10523.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | long double n,a, i,j, sum=0; 7 | while(scanf("%lf %lf", &n, &a)!=EOF) 8 | { 9 | sum=0; 10 | for(i=1; i<=n; i++) sum+=i*pow(a,i); 11 | printf("%.0lf\n", sum); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /UVa/10533.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int is_prime(int n) 5 | { 6 | int i; 7 | 8 | for(i=2; i<=sqrt(n); i++) 9 | { 10 | if(n%i==0) return 0; 11 | } 12 | return 1; 13 | } 14 | 15 | int digit_sum(int n) 16 | { 17 | int t=0; 18 | while(n) 19 | { 20 | t=t+n%10; 21 | n=n/10; 22 | } 23 | return t; 24 | } 25 | 26 | int main() 27 | { 28 | int n, t1, t2, x; 29 | scanf("%lld", &n); 30 | 31 | while(n) 32 | { 33 | int count=0; 34 | scanf("%d %d", &t1, &t2); 35 | for(x=t1; x<=t2; x++) if(is_prime(x)==1) if(is_prime(digit_sum(x))==1) count++; 36 | 37 | printf("%d\n", count); 38 | n--; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /UVa/10611 - The Playboy Chimp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n, ladies[50005], q, luchu; 8 | 9 | while(scanf("%d", &n) != EOF) { 10 | 11 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n=0, a=0,b, t=2; 8 | cin >> a; 9 | cout << a << endl;; 10 | 11 | 12 | while(cin >> n) { 13 | if(t%2) { 14 | 15 | if() 16 | 17 | t++; 18 | } 19 | else { 20 | 21 | t++; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /UVa/10633.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | unsigned long long int n, ans; 6 | while(scanf("%llu", &n)!=EOF) 7 | { 8 | 9 | if(n==0) break; 10 | ans=10*n/9; 11 | if(!(n%9)) printf("%llu %llu\n", ans-1, ans); 12 | else printf("%llu\n", 10*n/9); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/10684 net.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int subset[10002]; 4 | 5 | int main(){ 6 | static unsigned n, i; 7 | static int sum, max; 8 | 9 | while(scanf("%u", &n) && n){ 10 | 11 | sum = max = i = 0; 12 | 13 | for(; i < n; ++i){ 14 | scanf("%d", &subset[i]); 15 | sum += subset[i]; 16 | 17 | if(sum < 0) 18 | sum = 0; 19 | 20 | if(sum > max) 21 | max = sum; 22 | } 23 | 24 | if(max > 0) 25 | printf("The maximum winning streak is %d.\n", max); 26 | else 27 | printf("Losing streak.\n"); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /UVa/10684- [learn kadane's algo].c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ///KADANE'S ALGO TO GET MAX SUM SUB ARRAY 4 | 5 | int main() 6 | { 7 | int n, max=0, temp=0, a, i; 8 | while(scanf("%d", &n) && n) 9 | { 10 | max=0; 11 | temp=0; 12 | for(i=0; imax) 20 | { 21 | max=temp; 22 | } 23 | 24 | } 25 | if(temp>max) 26 | { 27 | max=temp; 28 | } 29 | if(max>0) printf("The maximum winning streak is %d.\n", max); 30 | else printf("Losing streak.\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVa/10696 f91.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | 7 | while(scanf("%d", &n) && n) 8 | { 9 | if(n<=100) printf("f91(%d) = 91\n", n); 10 | else printf("f91(%d) = %d\n", n, n-10); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/10699.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int n, i,j, rt, count; 6 | 7 | while((scanf("%d", &n))) 8 | { 9 | count=0; 10 | j=n; 11 | if(!n) break; 12 | rt=n/2; 13 | for(i=2; i<=rt; i++) 14 | { 15 | if(j%i==0) 16 | { 17 | count++; 18 | while(!(j%i)) j=j/i; 19 | } 20 | } 21 | if(n==j) count++; 22 | printf("%d : %d\n", n, count); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /UVa/10771.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, m, k; 5 | 6 | while(scanf("%d %d %d", &n, &m, &k)==3) 7 | { 8 | while(1) 9 | { 10 | if(k=0) 11 | { 12 | printf("Gared\n"); 13 | break; 14 | } 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /UVa/10773.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int t, i; 6 | double P,d, v, u; 7 | scanf("%d", &t); 8 | 9 | for(i=1; i<=t; i++) 10 | { 11 | scanf("%lf %lf %lf", &d, &v, &u); 12 | if(u>v && u>0 && v>0) 13 | { 14 | P=( d*(1/(sqrt( u*u*1.0- v*v*1.0))-1/u)); 15 | printf("Case %d: %0.3lf\n", i, P); 16 | } 17 | else printf("Case %d: can't determine\n", i); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/10783.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, a,b; 6 | 7 | scanf("%d", &t); 8 | for(i=1; i<=t; i++) 9 | { 10 | scanf("%d %d", &a, &b); 11 | if(!(a%2) && a) a=a+1; 12 | if(!(b%2) && b) b=b-1; 13 | a=(b+1)*(b+1)/4-(a-1)*(a-1)/4; 14 | printf("Case %d: %d\n", i, a); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /UVa/10784.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int N; 7 | long double n; 8 | 9 | while(1) 10 | { 11 | scanf("%d", &N); 12 | if(N==0) break; 13 | 14 | n=(-3.0+sqrt(9.0+8.0*N))/2.0; 15 | 16 | if(n==(int) n) printf("%d\n", (int) n+3); 17 | else printf("%d\n",(int) n+4); 18 | } 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /UVa/10812.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | short int n, s, d; 6 | scanf("%d", &n); 7 | 8 | while(n) 9 | { 10 | scanf("%hd %hd", &s, &d); 11 | if(s>=d && s%2==d%2) printf("%hd %hd\n",(s+d)/2, (s-d)/2); 12 | else printf("impossible\n"); 13 | n--; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/10879.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, n, a,b, j, rt, count; 6 | scanf("%d", &t); 7 | for(i=1; i<=t; i++) 8 | { 9 | scanf("%d", &n); 10 | count=0; 11 | printf("Case #%d: %d",i,n); 12 | 13 | 14 | for(j=2; j<=n; j++) 15 | { 16 | if(!(n%j)) 17 | { 18 | printf(" = %d * %d", j,n/j); 19 | count++; 20 | } 21 | if(count==2) 22 | { 23 | break; 24 | } 25 | } 26 | putchar('\n'); 27 | } 28 | return 0; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /UVa/10970.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m, n; 6 | while((scanf("%d %d", &m, &n))!=EOF) 7 | { 8 | printf("%d\n", m*n-1); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /UVa/11000.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int i, j, k, n, ansa, ansm; 6 | 7 | while(scanf("%lld", &n)) 8 | { 9 | if(n==-1) break; 10 | ansa=1; 11 | ansm=0; 12 | i=0; 13 | j=1; 14 | while(n) 15 | { 16 | k=i+j; 17 | i=j; 18 | j=k; 19 | ansm=ansa; 20 | ansa=ansa+k; 21 | n--; 22 | } 23 | 24 | printf("%lld %lld\n",ansm, ansa); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /UVa/11044.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t, r,c; 6 | scanf("%d", &t); 7 | while(t--) 8 | { 9 | scanf("%d %d", &r, &c); 10 | printf("%d\n", (r/3)*(c/3)); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /UVa/11152.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define pi 3.141592653589793 4 | int main() 5 | { 6 | int a, b, c; 7 | double s, rout, rin, tri, inarea; 8 | while(scanf("%d %d %d", &a, &b, &c)==3) 9 | { 10 | s=(a+b+c)/2.0; 11 | tri=sqrt(s*(s-a)*(s-b)*(s-c)); 12 | 13 | rout=(a*b*c)/(4.0*tri); 14 | rin=(tri/s); 15 | 16 | inarea=(pi*rin*rin); 17 | 18 | printf("%.4lf %.4lf %.4lf\n", (pi*rout*rout)-tri, tri-inarea, inarea); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /UVa/11172.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t, i; 6 | long int a, b; 7 | scanf("%d", &t); 8 | for(i=0; ib) printf(">\n"); 13 | else printf("=\n"); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/11185.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, i, j; 6 | char ter[25], temp; 7 | while((scanf("%d", &n))) 8 | { 9 | if(n<0) break; 10 | if(!n) 11 | { 12 | printf("0\n"); 13 | continue; 14 | } 15 | i=0; 16 | while(n) 17 | { 18 | ter[i]=(n%3)+'0'; 19 | n=n/3; 20 | i++; 21 | } 22 | ter[i]='\0'; 23 | i--; 24 | j=0; 25 | while(j 2 | #include 3 | int main() 4 | { 5 | int g,i, len; 6 | 7 | while(scanf("%d", &g)==1) 8 | { 9 | if(!g) break; 10 | getchar(); 11 | char str[101]; 12 | gets(str); 13 | len=strlen(str); 14 | g=len/g; 15 | 16 | for(i=g-1; i<=len; i=i+g) 17 | { 18 | int ex=0; 19 | while(ex 2 | #include 3 | int main() 4 | { 5 | int g,i,j, len; 6 | 7 | while(scanf("%d", &g)==1) 8 | { 9 | if(!g) break; 10 | getchar(); 11 | char str[101]; 12 | gets(str); 13 | len=strlen(str); 14 | g=len/g; 15 | char out[g+1]; 16 | for(i=0; i=0; j--) 20 | { 21 | out[j]=str[i+ex]; 22 | ex++; 23 | } 24 | out[g]='\0'; 25 | printf("%s", out); 26 | } 27 | putchar('\n'); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /UVa/11219 shuvo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int bd, bm,by, cd, cm, cy, tc, i; 6 | float age; 7 | scanf("%d", &tc); 8 | for(i=1;i<=tc; i++){ 9 | scanf("%d/%d/%d",&cd,&cm,&cy); 10 | scanf("%d/%d/%d",&bd,&bm,&by); 11 | age=(cy-by)+((cm-bm)*30+ (cd-bd))/365.0; 12 | if(age<0) printf("Case #%d: Invalid birth date\n",i); 13 | else if(age>130) printf("Case #%d: Check birth date\n",i); 14 | else printf("Case #%d: %d\n",i, (int)age); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /UVa/11231.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int r,c, b; 6 | 7 | while(scanf("%d %d %d", &r, &c, &b) && (r || c || b)) printf("%d\n", ( (r-7)*(c-7)+b)/2); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /UVa/11235 random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 10000000000LL 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | freopen("11235i.txt", "w", stdout); 9 | 10 | int n = 500; 11 | cout << n << endl; 12 | for(int i=1; i<=n; i++) { 13 | for(int j=1; j<=n; j++) { 14 | printf("%d ", rand() % MOD); 15 | } 16 | cout << endl; 17 | } 18 | 19 | int q = 50000; 20 | cout << q << endl; 21 | for(int i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | long long int n, a,b, sum, na, v, dif; 7 | while(scanf("%lld", &n) && n!=-1) 8 | { 9 | a=1; 10 | b= (int) ((double) (-1.0+sqrt(1+8*n))/2.0+ 0.999999); 11 | sum=b*(b+1)/2; 12 | while(sum!=n) 13 | { 14 | if(sum 2 | #include 3 | 4 | int main() 5 | { 6 | double n,p; 7 | double ans; 8 | while(scanf("%lf%lf",&n,&p)==2) 9 | { 10 | ans=pow(p,1/n); 11 | printf("%.0lf\n",ans); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /UVa/11332 - Summing Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | ll n; 9 | while(scanf("%lld", &n) && n) { 10 | 11 | ll ans = 0; 12 | while(n) { 13 | ans += n%10; 14 | n/=10; 15 | if(ans > 9) { 16 | ans = ans%10 + ans/10; 17 | } 18 | } 19 | printf("%lld\n", ans); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /UVa/11344 net.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char M[ 1003 ]; 4 | int n, s; 5 | 6 | int main() 7 | { 8 | int N; 9 | 10 | scanf("%d",&N); 11 | while ( N-- ) 12 | { 13 | gets( M ); 14 | gets( M ); 15 | scanf("%d",&n); 16 | bool ok = true; 17 | for (int i=0; i 2 | #include 3 | int main() 4 | { 5 | long long int n,s,i,j,p,l,k,a[100]; 6 | char m[1000000]; 7 | scanf("%lld",&n); 8 | while(n--){ 9 | scanf("%s",m); 10 | scanf("%lld",&s); 11 | for(i=0;i 2 | 3 | int main() 4 | { 5 | int t,i, m ; 6 | scanf("%d", &t); 7 | 8 | for(i=1; i<=t; i++) 9 | { 10 | int x1=-10000,y1=-10000, x2=10000,y2=10000, xt1,yt1,xt2,yt2; 11 | scanf("%d", &m); 12 | while(m) 13 | { 14 | scanf("%d %d %d %d", &xt1, &yt1, &xt2, &yt2); 15 | if(xt1>x1) x1=xt1; 16 | if(yt1>y1) y1=yt1; 17 | if(xt2 2 | 3 | int main() 4 | { 5 | int t,g,l; 6 | scanf("%d", &t); 7 | while(t) 8 | { 9 | scanf("%d %d", &g, &l); 10 | if(l%g==0) printf("%d %d\n", g, l); 11 | else printf("-1\n"); 12 | t--; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/11388!!!.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int t, g, l, a, b; 6 | scanf("%d", &t); 7 | while(t) 8 | { 9 | scanf("%d %d", &g, &l); 10 | for(a=g; a<=sqrt(g*l); a++) 11 | { 12 | b=g*l/a; 13 | if(a%g==0 && b%g==0) 14 | { 15 | printf("%d %d\n",(int) a, (int) b); 16 | break; 17 | } 18 | else printf("%d\n", -1); 19 | } 20 | t--; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /UVa/11428.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, x,y, i; 7 | float f, rt; 8 | 9 | while(scanf("%d", &n)==1) 10 | { 11 | if(!n) break; 12 | 13 | rt=pow(n, 1/3.0); 14 | for(i=1; i<60; i++) 15 | { 16 | f=pow(n+i*i*i, 1/3.0); 17 | if(f==(int)f) 18 | { 19 | printf("%.0lf %d\n", f, i); 20 | goto done; 21 | } 22 | } 23 | printf("No solution\n"); 24 | done: continue; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /UVa/11461.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a, b, ra, rb; 7 | while(1) 8 | { 9 | scanf("%d %d", &a, &b); 10 | if(!a && !b) break; 11 | 12 | ra=sqrt(a-1); 13 | rb=sqrt(b); 14 | 15 | printf("%d\n", rb-ra); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/11462 shahin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int cmpfunc (const void * a, const void * b) 5 | { 6 | return ( *(int*)a - *(int*)b ); 7 | } 8 | int ara[2000005]; 9 | main() 10 | { 11 | int n,i; 12 | while(scanf("%d",&n)!=EOF){ 13 | if(n==0){ 14 | break; 15 | } 16 | for(i=0;i 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n, i,j; 8 | 9 | while((scanf("%d", &n))) 10 | { 11 | if(n==0) break; 12 | char age[n][3], t[3]; 13 | for(i=0; iatoi(age[j])) 16 | { 17 | strcpy(t,age[i]); 18 | strcpy(age[i],age[j]); 19 | strcpy(age[j],t); 20 | } 21 | printf("%s", age[0]); 22 | for(i=1; i 2 | 3 | int main() 4 | { 5 | int t,i; 6 | long int a,b,c; 7 | 8 | scanf("%d", &t); 9 | for(i=1; i<=t; i++) 10 | { 11 | scanf("%ld %ld %ld", &a, &b, &c); 12 | if(a<=0 || b<=0 || c<=0 || a+b<=c || b+c<=a || c+a<=b) printf("Case %d: Invalid\n", i); 13 | else if(a==b && a==c) printf("Case %d: Equilateral\n", i); 14 | else if(a==b || b==c || c==a) printf("Case %d: Isosceles\n", i); 15 | else printf("Case %d: Scalene\n", i); 16 | } 17 | 18 | return 0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /UVa/11498.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, ox,oy, x,y; 6 | while(scanf("%d", &n)) 7 | { 8 | if(!n) return 0; 9 | scanf("%d %d", &ox, &oy); 10 | 11 | while(n) 12 | { 13 | scanf("%d %d", &x, &y); 14 | if(x==ox || y==oy) printf("divisa\n"); 15 | else if(xoy) printf("NO\n"); 16 | else if(x>ox && y>oy) printf("NE\n"); 17 | else if(x>ox && y 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin >> t; 8 | while(t--) { 9 | 10 | int n,m, u,v; 11 | vectorgraph[100005]; 12 | 13 | cin >> n >> m; 14 | for(int i=0; i> u >> v; 16 | graph[v].push_back(u); 17 | } 18 | 19 | int temp=0; 20 | 21 | for(int i=1; i<=n; i++) 22 | if(!graph[i].size()) 23 | temp++; 24 | 25 | if(temp) cout << temp << endl; 26 | else cout << 1 << endl; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /UVa/11512 random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 100 3 | 4 | using namespace std; 5 | 6 | char ch[] = {'A', 'C' , 'G', 'T' }; 7 | 8 | int main() { 9 | srand(time(NULL)); 10 | freopen("11512i.txt", "w", stdout); 11 | int T = 100; 12 | cout << T << endl; 13 | while(T--) { 14 | int n = rand() % MAX; 15 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int t,i, press; 6 | char c; 7 | scanf("%d", &t); 8 | getchar(); 9 | for(i=1; i<=t; i++) 10 | { 11 | 12 | c=1; 13 | press=0; 14 | while(c!='\n') 15 | { 16 | scanf("%c", &c); 17 | if(c==' ' || c=='a' || c=='d' || c=='g' || c=='j' || c=='m' || c=='p' || c=='t' || c=='w') press++; 18 | else if(c=='b' || c=='e' || c=='h' || c=='k' || c=='n' || c=='q' || c=='u' || c=='x') press+=2; 19 | else if(c=='c' || c=='f' || c=='i' || c=='l' || c=='o' || c=='r' || c=='v' || c=='y') press+=3; 20 | else if(c=='s' || c=='z' ) press+=4; 21 | } 22 | printf("Case #%d: %d\n", i, press); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /UVa/11547.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t, n; 6 | scanf("%d", &t); 7 | 8 | while(t) 9 | { 10 | scanf("%d", &n); 11 | n=(63*n+7492)*5-498; 12 | n=n-((int)(n/100))*100; 13 | if(n<0) n=n*-1; 14 | printf("%d\n", (n/10)); 15 | t--; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/11577.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str[6]; 7 | int n=1; 8 | 9 | while(n) 10 | { 11 | gets(str); 12 | if(strcmp(str, "*")==0) break; 13 | else if(!strcmp(str, "Hajj")) printf("Case %d: Hajj-e-Akbar\n", n); 14 | else printf("Case %d: Hajj-e-Asghar\n", n); 15 | n++; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/11614.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | long long int n, i; 8 | scanf("%d", &t); 9 | while(t) 10 | { 11 | scanf("%lld", &n); 12 | i=(-1+sqrt(1+8*n))/2; 13 | printf("%lld\n",i); 14 | t--; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /UVa/11677.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int h1, m1, h2, m2, total; 6 | while((scanf("%d %d %d %d", &h1, &m1, &h2, &m2)==4)) 7 | { 8 | if(h1==0 && m1==0 && h2==0 && m2==0) break; 9 | total=(h2*60+m2)-(h1*60+m1); 10 | if(total<0) printf("%d\n", 1440+total); 11 | else printf("%d\n", total); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /UVa/11723.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int R, N, D, i=1; 6 | while((scanf("%d %d", &R, &N))==2) 7 | { 8 | if(!R || !N) break; 9 | D=(R-1)/N; 10 | if(D>26) printf("Case %d: impossible\n", i); 11 | else printf("Case %d: %d\n", i, D); 12 | i++; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/11727.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T, i, a, b, c; 6 | 7 | scanf("%d", &T); 8 | for(i=1; i<=T; i++) 9 | { 10 | scanf("%d %d %d", &a, &b, &c); 11 | if((a>b && ac)) printf("Case %d: %d\n", i, a); 12 | else if((b>c && ba)) printf("Case %d: %d\n", i, b); 13 | else printf("Case %d: %d\n", i, c); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/11764- mario.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, w, h,next, high, low; 6 | scanf("%d", &t); 7 | for(i=1;i<=t; i++) 8 | { 9 | high=0; 10 | low=0; 11 | scanf("%d", &w); 12 | scanf("%d", &h); 13 | while(w>1) 14 | { 15 | scanf("%d", &next); 16 | if(next>h) high++; 17 | else if(next 2 | 3 | int main() 4 | { 5 | int n,i, t1,t2,tf,a, ct1,ct2,ct3, total, ct; 6 | 7 | scanf("%d", &n); 8 | for(i=1; i<=n; i++) 9 | { 10 | scanf("%d %d %d %d %d %d %d", &t1, &t2, &tf, &a, &ct1, &ct2, &ct3); 11 | if(ct1<=ct2 && ct1<=ct3) ct=(ct2+ct3)/2; 12 | else if(ct2<=ct1 && ct2<=ct3) ct=(ct1+ct3)/2; 13 | else ct=(ct1+ct2)/2; 14 | 15 | total=t1+t2+tf+a+ct; 16 | 17 | printf("Case %d: ", i); 18 | 19 | if(total>=90) printf("A\n"); 20 | else if(total>=80 && total<90) printf("B\n"); 21 | else if(total>=70 && total<80) printf("C\n"); 22 | else if(total>=60 && total<70) printf("D\n"); 23 | else printf("F\n"); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /UVa/11799.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, n, h,s; 6 | scanf("%d", &t); 7 | for(i=1; i<=t; i++) 8 | { 9 | scanf("%d", &n); 10 | scanf("%d", &h); 11 | while(n>1) 12 | { 13 | scanf("%d", &s); 14 | if(s>h) h=s; 15 | n--; 16 | } 17 | printf("Case %d: %d\n", i, h); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVa/11805 sakib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i,T; 6 | scanf("%d", &T); 7 | for(i=1; i<=T; i++){ 8 | int N,K,P; 9 | scanf ("%d %d %d",&N,&K,&P); 10 | int M=K+P; 11 | if (M>N) { 12 | while(M>N) M=M-N; 13 | printf ("Case %d: %d\n",i,M); 14 | } 15 | else printf ("Case %d: %d\n",i,M); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/11805.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, n, k, p, f; 6 | scanf("%d", &t); 7 | for(i=1; i<=t; i++) 8 | { 9 | scanf("%d %d %d", &n, &k, &p); 10 | f= (p%n) + k; 11 | if(f>n) printf("Case %d: %d\n", i, f-n); 12 | else printf("Case %d: %d\n", i, f); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/11853 - Paintball.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /UVa/11875 sakib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N,j=0; 6 | 7 | scanf ("%d",&N); 8 | 9 | int ara[N]; 10 | for (j=0;j 2 | 3 | int main() 4 | { 5 | int T, N, i=1, j=0; 6 | scanf("%d", &T); 7 | while(i<=T) 8 | { 9 | scanf("%d", &N); 10 | int age[N]; 11 | for(j=0; j 2 | int main(){ 3 | int n; 4 | int c=0; 5 | while(scanf("%d",&n)==1){ 6 | if(n==0) 7 | break; 8 | c=0; 9 | while(n>=3){ 10 | 11 | n=n-3; 12 | c++; 13 | n++; 14 | } 15 | if(n==2) 16 | printf("%d\n",(c+1)); 17 | else 18 | printf("%d\n",c); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /UVa/11877.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | 7 | while(((scanf("%d", &n))==1)) 8 | { 9 | if(n) printf("%d\n", n/2); 10 | else break; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/11879 raida.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int a,j,i,size; 6 | char n[1000]; 7 | while(scanf("%s",&n)!=0){ 8 | if((n[0]-'0')==0){ 9 | break; 10 | } 11 | size = strlen(n); 12 | j=0; 13 | for(i = 0;i 2 | #include 3 | #include 4 | int main() 5 | { 6 | char num[1000] ; 7 | int n, d; 8 | 9 | while((gets(num))) 10 | { 11 | if(num[0]-'0'==0 && num[1]=='\0') break; 12 | n=strlen(num); 13 | d=(num[n-1]-'0'); 14 | num[n-1]='\0'; 15 | if((atoi(num)-5*d)%17==0) printf("1\n"); 16 | else printf("0\n"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /UVa/11879raida2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char j,i,size; 6 | char n[102]; 7 | while(scanf("%s",&n)){ 8 | if((n[0]=='0') && n[1]=='\0'){ 9 | break; 10 | } 11 | size = strlen(n); 12 | j=0; 13 | for(i = 0;i 2 | int main() 3 | { 4 | int t,k,n,p,q,i,a[32],sum; 5 | scanf("%d",&t); 6 | for(k=1;k<=t;k++) 7 | { 8 | scanf("%d %d %d",&n,&p,&q); 9 | for(i=0;i=p || sum+a[i]>q) break; 14 | else sum+=a[i]; 15 | } 16 | 17 | 18 | printf("Case %d: %d\n",k,i); 19 | 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /UVa/11900.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, n,p,q, j, sumt, w[32]; 6 | scanf("%d", &t); 7 | for(i=1; i<=t; i++) 8 | { 9 | scanf("%d %d %d", &n, &p, &q); 10 | 11 | for(j=0; j 2 | #include 3 | int main() 4 | { 5 | double l,w,h,tanth; 6 | 7 | while((scanf("%lf %lf %lf %lf", &l, &w, &h, &tanth))==4) 8 | { 9 | tanth=tan(tanth*acos(-1)/180.0); 10 | 11 | if(tanth<=h/l) printf("%.3lf mL\n", l*w*(h-0.5*l*tanth)); 12 | else printf("%.3lf mL\n", 0.5*h*h*w/tanth); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/11934.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int a,b,c,d,x, count, rt; 6 | while((scanf("%lld %lld %lld %lld %lld", &a, &b, &c, &d, &x))==5) 7 | { 8 | if(!a && !b && !c && !d && !x) break; 9 | count=0; 10 | while(x>=0) 11 | { 12 | rt=a*x*x+b*x+c; 13 | if(!(rt%d)) count++; 14 | x--; 15 | } 16 | printf("%lld\n", count); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /UVa/11984.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,i, c, df, cn; 6 | scanf("%d", &n); 7 | for(i=1; i<=n; i++) 8 | { 9 | scanf("%d %d", &c, &df); 10 | printf("Case %d: %.2lf\n", i, df*5.0/9.0+c); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/12114 - Bachelor Arithmetic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t=1,n,m; 7 | while(scanf("%d %d", &n,&m)) { 8 | if(!n && !m) return 0; 9 | 10 | if(n == 1) { 11 | printf("Case %d: :-\\\n", t++); 12 | } 13 | else if(n <= m) { 14 | printf("Case %d: :-|\n", t++); 15 | } 16 | else { 17 | printf("Case %d: :-(\n", t++); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UVa/12136 - Schedule of a Married Man.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int p,q,r,s, x,y, a,b; 6 | 7 | int main() { 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | scanf("%d:%d %d:%d", &p,&q,&r,&s); 12 | x = p*60 + q; y = r*60 + s; 13 | scanf("%d:%d %d:%d", &p,&q,&r,&s); 14 | a = p*60 + q; b = r*60 + s; 15 | 16 | if( (a >= x && a <= y) || (b >= x && b <= y) ) printf("Case %d: Mrs Meeting\n", t); 17 | else if( (x >= a && x <= b) || (y >= a && y <= b) ) printf("Case %d: Mrs Meeting\n", t); 18 | else printf("Case %d: Hits Meeting\n", t); 19 | } 20 | 21 | } 22 | //scanf("%d:%d %d:%d", &p,&q,&r,&s); 23 | //Case 2: Hits Meeting 24 | //Case 3: Mrs Meeting 25 | -------------------------------------------------------------------------------- /UVa/12140 - Magic Rings DP+GEO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T; t++) { 9 | scanf("%d %d", &n,&m) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /UVa/12149.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | while(1) 7 | { 8 | scanf("%d", &n); 9 | if(!n) break; 10 | printf("%d\n", n*(n+1)*(2*n+1)/6); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /UVa/12191 rand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LIM 10005 3 | #define ALPH 5 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | srand(time(NULL)); 9 | 10 | freopen("12191i.txt", "w", stdout); 11 | 12 | int T = 10; 13 | while(T--) { 14 | int n = rand() % LIM + 1; 15 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int t=1, pola,maiya, p,m, a, i,j; 6 | while(scanf("%d %d", &pola, &maiya) && (pola || maiya)) 7 | { 8 | scanf("%d", &p); 9 | for(i=1; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | // scanf("%d", &T); 8 | for(int t=1; ; t++) { 9 | int n,x, ans = 0; 10 | scanf("%d", &n); 11 | if(!n) return 0; 12 | while(n--) { 13 | scanf("%d", &x); 14 | if(x) ans++; 15 | else ans--; 16 | } 17 | printf("Case %d: %d\n", t, ans); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /UVa/12284 - Digital Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T ;t++) { 9 | scanf("%d %d", &n,&k); 10 | for(int i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | int n, i; 7 | char word[10]; 8 | scanf("%d", &n); 9 | while(n) 10 | { 11 | scanf("%s", &word); 12 | if(strlen(word)==5) printf("3\n"); 13 | else 14 | { 15 | int o=0, t=0; 16 | for(i=0; it) printf("1\n"); 22 | else printf("2\n"); 23 | } 24 | n--; 25 | } 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /UVa/1230.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long long int bigmod (long long int b, long long int p, long long int m) 4 | { 5 | long long int r; 6 | 7 | if(!p) return 1; 8 | else if(p%2) 9 | { 10 | p=p-1; 11 | return (bigmod(b,p,m)*(b%m))%m; 12 | } 13 | else 14 | { 15 | p=p/2; 16 | r=bigmod(b,p,m); 17 | return ((r%m)*(r%m))%m; 18 | } 19 | } 20 | 21 | int main() 22 | { 23 | long long int b,p,m; 24 | long long int n; 25 | scanf("%lld", &n); 26 | while(n) 27 | { 28 | scanf("%lld %lld %lld", &b,&p,&m); 29 | printf("%lld\n", bigmod(b,p,m)); 30 | n--; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVa/12372.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i, a,b,c; 6 | scanf("%d", &t); 7 | for(i=1; i<=t; i++) 8 | { 9 | scanf("%d %d %d", &a, &b, &c); 10 | if(a>20 || b>20 || c>20) printf("Case %d: bad\n",i); 11 | else printf("Case %d: good\n", i); 12 | 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /UVa/12403.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int sum=0; 6 | int am; 7 | char t; 8 | char op[7]; 9 | scanf("%d", &t); 10 | 11 | while(t) 12 | { 13 | scanf("%s", op); 14 | if(op[0]=='d') 15 | { 16 | scanf("%d", &am); 17 | sum=sum+am; 18 | } 19 | else printf("%d\n", sum); 20 | t--; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /UVa/12405 - Scarecrow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T,t, n, i,j, sc=0; 6 | char f[105]; 7 | 8 | scanf("%d", &T); 9 | for(t=1; t<=T; t++) 10 | { 11 | sc=0; 12 | scanf("%d", &n); 13 | scanf("%s", f); 14 | 15 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int a,b, dif; 6 | while((scanf("%d %d", &a, &b))==2) 7 | { 8 | if(a==-1 && b==-1) break; 9 | printf("%d %d\n", a,b); 10 | dif=abs(b-a); 11 | if(dif<=50) printf("%d\n", dif); 12 | else printf("%d\n", 100-dif); 13 | 14 | } 15 | return 0; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /UVa/12474 - Draw and Score.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /UVa/12478.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("KABIR\n"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /UVa/12499 - I am Dumb 3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,l, x, ara[55]; 6 | 7 | int main() { 8 | 9 | int T; 10 | scanf("%d", &T); 11 | for(int t=1; t<=T; t++) { 12 | 13 | scanf("%d %d",&n, &l); 14 | 15 | int xorSum = 0; 16 | 17 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int t, x,y,z; 6 | scanf("%d", &t); 7 | while(t) 8 | { 9 | scanf("%d %d %d", &x, &y, &z); 10 | printf("%d\n", z*(2*x-y)/(x+y)); 11 | t--; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /UVa/12517.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m, n,i; 6 | while((scanf("%d %d", &m, &n))) 7 | { 8 | if(!m && !n) break; 9 | int sum=0; 10 | for(i=m; i<=n; i++) 11 | { 12 | m=i; 13 | while(m) 14 | { 15 | sum=sum+m%10; 16 | m=m/10; 17 | } 18 | } 19 | printf("%d\n", sum); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /UVa/12578.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int t, l; 6 | double ca; 7 | 8 | scanf("%d", &t); 9 | 10 | while(t) 11 | { 12 | scanf("%d", &l); 13 | ca= acos(-1)*l*l/25.0; 14 | printf("%.2lf %.2lf\n", ca, 3.0*l*l/5.0-ca); 15 | t--; 16 | } 17 | 18 | return 0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /UVa/12611 - Beautiful Flag.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T; t++) { 9 | int r, l,w; 10 | scanf("%d", &r); 11 | l = 5*r; 12 | w = l/5*3; 13 | 14 | printf("Case %d:\n", t); 15 | printf("%d %d\n", -l*45/100, w/2); 16 | printf("%d %d\n", +l*55/100, w/2); 17 | printf("%d %d\n", +l*55/100, -w/2); 18 | printf("%d %d\n", -l*45/100, -w/2); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UVa/12611.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,i, r, x1, x2, y; 6 | scanf("%d", &n); 7 | for(i=1; i<=n; i++) 8 | { 9 | scanf("%d", &r); 10 | x1=-1*9*r/4; 11 | x2=11*r/4; 12 | y=3*r/2; 13 | 14 | printf("Case %d:\n%d %d\n%d %d\n%d %d\n%d %d\n", i, x1, y, x2, y, x2, -1*y, x1, -1*y); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /UVa/12716 - GCD XOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define LIM 30000000 4 | 5 | using namespace std; 6 | 7 | int n; 8 | ll ans[LIM+10]; 9 | 10 | int main() { 11 | 12 | for(int g=1; g<=LIM; g++) { 13 | for(int a=g+g; a<=LIM; a+=g) { 14 | int b = a - g; 15 | // cout << g << ' ' << a << ' ' << b << ' ' << (a^b) << endl; 16 | if( (a^b) == g) { 17 | // cout << "ADD!" << endl; getchar(); 18 | ans[a]++; 19 | } 20 | } 21 | } 22 | for(int i=1; i<=LIM; i++) ans[i] += ans[i-1]; 23 | 24 | 25 | int T; 26 | scanf("%d", &T); 27 | for(int t=1; t<=T; t++) { 28 | scanf("%d", &n); 29 | printf("Case %d: %lld\n", t, ans[n]); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVa/12716 brute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | freopen("12716ac.txt", "w", stdout); 8 | 9 | int n; 10 | while( (cin >> n) && n ) { 11 | cout << "DEBUG " << n << endl; 12 | int cnt = 0; 13 | for(int i=1; i<=n; i++) { 14 | for(int j=i; j<=n; j++) { 15 | if(__gcd(i,j) == (i^j)) { 16 | cout << (i^j) << ' ' << i << ' ' << j << endl; 17 | cnt++; 18 | } 19 | } 20 | } 21 | cout << "OUTPUT : " << cnt << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /UVa/13148 - A Giveaway.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | while(scanf("%d", &n) && n) { 8 | if(n == 1 || n == 64 || n == 729 || n == 4096 || n == 15625 || n == 46656 || n == 117649 || n == 262144 || n == 531441 || n == 1000000 || 9 | n == 1771561 || n == 2985984 || n == 4826809 || n == 7529536 || n == 11390625 || n == 16777216 || n == 24137569 || n == 34012224 || 10 | n == 47045881 || n == 64000000 || n == 85766121) 11 | printf("Special\n"); 12 | else printf("Ordinary\n"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /UVa/13275 - Leap Birthdays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | for(int t=1; t<=T;t++) { 9 | int d,m,y,Y; 10 | scanf("%d %d %d %d", &d,&m,&y,&Y); 11 | if(d == 29 && m == 2) { 12 | int ans = 0; 13 | for(int i=y+4; i<=Y; i+=4) { 14 | if(i%400==0) ans++; 15 | else if(i%100) ans++; 16 | } 17 | printf("Case %d: %d\n", t, ans); 18 | } 19 | else printf("Case %d: %d\n", t, Y-y); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UVa/13278 - Angry Birds Transformers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MIN 0 3 | #define MAX 10004 4 | using namespace std; 5 | 6 | int n, x,y, cnt[20004]; 7 | 8 | int main() { 9 | int T; 10 | // scanf("%d", &T); 11 | for(int t=1; ; t++) { 12 | memset(cnt, 0, sizeof cnt); 13 | scanf("%d", &n); 14 | if(!n) return 0; 15 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int mark, i,t,count; 6 | char s[80]; 7 | scanf("%d", &t); 8 | 9 | while(t) 10 | { 11 | scanf("%s", s); 12 | i=0; 13 | count=1; 14 | mark=0; 15 | while(s[i]!='\0') 16 | { 17 | if(s[i]=='O') 18 | { 19 | mark+=count; 20 | count++; 21 | } 22 | else count=1; 23 | i++; 24 | } 25 | printf("%d\n",mark); 26 | t--; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /UVa/1628 - Pizza Delivery.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /UVa/1648 - Business Center.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define EPS 1e-9 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | // freopen("1648i.txt", "r", stdin); 8 | // freopen("1648o.txt", "w", stdout); 9 | int n,m; 10 | while(scanf("%d %d", &n,&m) != EOF) { 11 | int ans = INT_MAX; 12 | for(int i=0; i= 0) ans = min(ans, y); 18 | // cout << y << endl; 19 | } 20 | printf("%d\n", ans); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /UVa/1729 - Owllen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | char str[100005]; 6 | 7 | int main() { 8 | int T; 9 | scanf("%d", &T); 10 | for(int t=1; t<=T; t++) { 11 | scanf("%s", str); 12 | int cnt[30] = {0}; 13 | int sz = strlen(str); 14 | for(int i=0; i 2 | #define LIM 4500 3 | #define vi vector 4 | #define pb(x) push_back(x) 5 | #define ll long long int 6 | 7 | using namespace std; 8 | 9 | int main() { 10 | // freopen("i.txt", "r", stdin); 11 | // freopen("o.txt", "w", stdout); 12 | int n; 13 | while(scanf("%d", &n) && n) { 14 | ll sq = sqrt(n); 15 | ll ans = n; 16 | ll last = n; 17 | for(int i=2; i<=sq; i++) { 18 | ll j = n/i; 19 | ans += i*j; 20 | ans += ( last*(last+1)/2 - j*(j+1)/2 ) * (i-1); 21 | last = j; 22 | } 23 | if(sq < last) { 24 | ans += ( last*(last+1)/2 - sq*(sq+1)/2 ) * sq; 25 | } 26 | printf("%lld\n", ans-1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /UVa/272- tex quotes.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char ch; 6 | char i=1; 7 | while((scanf("%c", &ch))!=EOF) 8 | { 9 | if(ch=='"') 10 | { 11 | if(i==1) 12 | { 13 | printf("``"); 14 | i=2; 15 | } 16 | else 17 | { 18 | printf("''"); 19 | i=1; 20 | } 21 | } 22 | else putchar(ch); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /UVa/299.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t, n,i,j, count, temp; 6 | scanf("%d", &t); 7 | while(t) 8 | { 9 | count=0; 10 | scanf("%d", &n); 11 | int ara[n]; 12 | for(i=0; iara[j]) 14 | { 15 | count++; 16 | temp=ara[i]; 17 | ara[i]=ara[j]; 18 | ara[j]=temp; 19 | } 20 | printf("Optimal train swapping takes %d swaps.\n", count); 21 | t--; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /UVa/369.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int n,k,k1; 6 | while((scanf("%lld %lld", &n, &k))==2) 7 | { 8 | if(!n && !k) break; 9 | 10 | k1=n-k; 11 | if(k1>k) k1=k; 12 | 13 | if(k1==0 || n==k1) 14 | { 15 | printf("%lld things taken %lld at a time is 1 exactly.\n",n,k); 16 | continue; 17 | } 18 | 19 | double comb=1.0, i; 20 | for (i = 1.0; i <= k1; i++) 21 | { 22 | comb*= (n - k1 + i); 23 | comb/=i; 24 | } 25 | 26 | printf("%lld things taken %lld at a time is %.0lf exactly.\n",n,k, comb); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /UVa/382 noboni.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() 4 | { 5 | long int N,i,sum,j; 6 | printf("PERFECTION OUTPUT\n"); 7 | while(scanf("%ld",&N)==1 && N!=0) 8 | { 9 | sum=1; 10 | for(i=2;i<=sqrt(N);i++) 11 | { 12 | j=N/i; 13 | if(N%i==0) 14 | sum=sum+i+j; 15 | } 16 | if(sum==N) 17 | printf("%5ld PERFECT\n",N); 18 | else if(sum>N) 19 | printf("%5ld ABUNDANT\n",N); 20 | else 21 | printf("%5ld DEFICIENT\n",N); 22 | } 23 | printf("END OF OUTPUT\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /UVa/382 test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int check(int n) 4 | { 5 | int i, sum=0; 6 | for(i=1; i<=n/2; i++) if(!(n%i)) sum=sum+i; 7 | if(n==sum) return 0; 8 | else if(n>sum) return -1; 9 | else return 1; 10 | } 11 | 12 | int main() 13 | { 14 | int num[101], i; 15 | for(i=0; ; i++) 16 | { 17 | scanf("%d", &num[i]); 18 | if(num[i]==0) break; 19 | } 20 | printf("PERFECTION OUTPUT\n"); 21 | for(i=0; ; i++) 22 | { 23 | if(num[i]==0) 24 | { 25 | printf("END OF OUTPUT\n"); 26 | break; 27 | } 28 | if(num[i]>10000) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /UVa/400483.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char inp[1000],c; 7 | int i; 8 | while(scanf("%s",inp)!=EOF) 9 | { 10 | c=getchar(); 11 | 12 | for(i=strlen(inp)-1; i>=0; i--) printf("%c",inp[i]); 13 | putchar(c); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /UVa/530.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | -------------------------------------------------------------------------------- /UVa/543.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int isprime(int n) 5 | { 6 | int i, rt=sqrt(n); 7 | for(i=2; i<=rt; i++) if(!(n%i)) return 0; 8 | return 1; 9 | } 10 | 11 | int main() 12 | { 13 | int n, b,a; 14 | 15 | while(1) 16 | { 17 | scanf("%d", &n); 18 | if(!n) break; 19 | b=n-3; 20 | a=3; 21 | while(b>=a) 22 | { 23 | if(!(isprime(b)) || !(isprime(a))) 24 | { 25 | b=b-2; 26 | a=a+2; 27 | } 28 | else break; 29 | } 30 | if(b>=a) printf("%d = %d + %d\n", n, a, b); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVa/580 - Critical Mass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int dp[35], ex[35]; 6 | 7 | int main() { 8 | ex[0] = 1; for(int i=1; i<=30; i++) ex[i] = ex[i-1]*2; 9 | dp[1] = 2; dp[2] = 4; dp[3] = 7; 10 | for(int i=4; i<=30; i++) dp[i] = dp[i-1] + dp[i-2] + dp[i-3]; 11 | 12 | int n; 13 | while(scanf("%d", &n)) { 14 | if(!n) return 0; 15 | printf("%d\n", ex[n] - dp[n]); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /UVa/686.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int isprime(int n) 5 | { 6 | int i, rt=sqrt(n); 7 | for(i=2; i<=rt; i++) if(!(n%i)) return 0; 8 | return 1; 9 | } 10 | 11 | int main() 12 | { 13 | int n, b,a, count; 14 | 15 | while(1) 16 | { 17 | 18 | scanf("%d", &n); 19 | if(!n) break; 20 | if(n==4) 21 | { 22 | printf("1\n"); 23 | continue; 24 | } 25 | b=n-3; 26 | a=3; 27 | count=0; 28 | while(b>=a) 29 | { 30 | if((isprime(b)) && (isprime(a))) count++; 31 | b=b-2; 32 | a=a+2; 33 | } 34 | printf("%d\n", count); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /UVa/834 nabil.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int num, den; 6 | 7 | while(scanf("%d%d", &num ,&den) == 2) 8 | { 9 | int n = 0, r[100] = {0}; 10 | 11 | printf("["); 12 | 13 | while(1){ 14 | r[n] = num/den; 15 | num = num%den; 16 | num = num + den; 17 | den = num - den; 18 | num = num - den; 19 | 20 | printf("%d", r[n]); 21 | 22 | if(n == 0) 23 | printf(";"); 24 | else 25 | printf(","); 26 | 27 | n++; 28 | 29 | if(den%num == 0) 30 | { 31 | printf("\b]\n"); 32 | break; 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /UVa/847 - A Multiplication Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int p; 7 | 8 | int main() { 9 | 10 | while(cin >> p) { 11 | //cout << getWin(1) << endl; 12 | int n=1; 13 | bool win = true; 14 | while(p > 1) { 15 | 16 | win = !win; 17 | 18 | if(!win) { 19 | p = (p+8)/9; 20 | //win = !win; 21 | } 22 | else { 23 | p = (p+1)/2; 24 | //win = !win; 25 | } 26 | //if(p <= 1) break; 27 | //else win = !win; 28 | } 29 | 30 | if(!win) cout << "Stan wins." << endl; 31 | else cout << "Ollie wins." << endl; 32 | } 33 | 34 | return 0; 35 | } 36 | --------------------------------------------------------------------------------