├── 1 A. Theatre Square.cpp ├── 1003 A. Polycarp's Pockets.cpp ├── 1005 A. Tanya and Stairways.cpp ├── 1005 B. Delete from the Left.cpp ├── 1006 A. Adjacent Replacements.cpp ├── 1017 A. The Rank.cpp ├── 1030 A. In Search of an Easy Problem.cpp ├── 1043 A. Elections.cpp ├── 1047 A. Little C Loves 3 I.cpp ├── 1051 B. Relatively Prime Pairs.cpp ├── 1060 A. Phone Numbers.cpp ├── 1061 A. Coins.cpp ├── 1065 A. Vasya and Chocolate.cpp ├── 1073 A. Diverse Substring.cpp ├── 1077 A. Frog Jumping.cpp ├── 1077 B. Disturbed People.cpp ├── 1080 A. Petya and Origami.cpp ├── 1081 A. Definite Game.cpp ├── 1088 A. Ehab and another construction problem.cpp ├── 1088 B. Ehab and subtraction.cpp ├── 1090 M. The Pleasant Walk.cpp ├── 1091 A. New Year and the Christmas Ornament.cpp ├── 1092 A. Uniform String.cpp ├── 1092 B. Teams Forming.cpp ├── 1093 A. Dice Rolling.cpp ├── 1093 B. Letters Rearranging.cpp ├── 1095 A. Repeating Cipher.cpp ├── 1095 B. Array Stabilization.cpp ├── 1096 A. Find Divisible.cpp ├── 1097 A. Gennady and a Card Game.cpp ├── 11 A. Increasing Sequence.cpp ├── 110 A. Nearly Lucky Number.cpp ├── 1101 A. Minimum Integer.cpp ├── 1102 A. Integer Sequence Dividing.cpp ├── 1104 A. Splitting into digits.cpp ├── 1106 C. Lunar New Year and Number Division.cpp ├── 1107 A. Digits Sequence Dividing.cpp ├── 1108 A. Two distinct points.cpp ├── 1110 A. Parity.cpp ├── 1111 A. Superhero Transformation.cpp ├── 1114 A. Got Any Grapes.cpp ├── 1118 A. Water Buying.cpp ├── 1121 A. Technogoblet of Fire.cpp ├── 1121 B. Mike and Children.cpp ├── 1130 A. Be Positive.cpp ├── 1133 A. Middle of the Contest.cpp ├── 1136 A. Nastya Is Reading a Book.cpp ├── 1138 A. Sushi for Two.cpp ├── 1139 B. Chocolates.cpp ├── 1141 A. Game 23.cpp ├── 1141 B. Maximal Continuous Rest.cpp ├── 1144 B. Parity Alternated Deletions.cpp ├── 1146 A. Love A.cpp ├── 1148 A. Another One Bites The Dust.cpp ├── 115 A. Party.cpp ├── 1150 A. Stock Arbitraging.cpp ├── 1150 B. Tiling Challenge.cpp ├── 1152 A. Neko Finds Grapes.cpp ├── 1153 A. Serval and Bus.cpp ├── 1154 A. Restoring Three Numbers.cpp ├── 1159 A. A pile of stones.cpp ├── 1162 A. Zoning Restrictions Again.cpp ├── 1163 A. Eating Soup.cpp ├── 1165 B. Polycarp Training.cpp ├── 1166 A. Silent Classroom.cpp ├── 1167 A. Telephone Number.cpp ├── 1173 A. Nauuo and Votes.cpp ├── 1174 A. Ehab Fails to Be Thanos.cpp ├── 1175 A. From Hero to Zero.cpp ├── 1176 A. Divide it!.cpp ├── 1177 A. Digits Sequence (Easy Edition).cpp ├── 118 A. String Task.cpp ├── 1180 A. Alex and a Rhombus.cpp ├── 1183 A. Nearest Interesting Number.cpp ├── 1183 B. Equalize Prices.cpp ├── 1185 A. Ropewalkers.cpp ├── 1186 A. Vus the Cossack and a Contest.cpp ├── 1187 A. Stickers and Toys.cpp ├── 1189 A. Keanu Reeves.cpp ├── 1191 A. Tokitsukaze and Enhancement.cpp ├── 1194 A. Remove a Progression.cpp ├── 1196 A. Three Piles of Candies.cpp ├── 1200 A. Hotelier.cpp ├── 1204 A. BowWow and the Timetable.cpp ├── 1206 A. Choose Two Numbers.cpp ├── 1206 B. Make Product Equal One.cpp ├── 1208 A. XORinacci.cpp ├── 1209 A. Paint the Numbers.cpp ├── 1213 A. Chips Moving.cpp ├── 1214 C. Bad Sequence.cpp ├── 1215 A.Yellow Cards.cpp ├── 1216 A. Prefixes.cpp ├── 1216 B. Shooting.cpp ├── 122 A. Lucky Division.cpp ├── 122 B. Lucky Substring.cpp ├── 1220 A. Cards.cpp ├── 1223 A. CME.cpp ├── 1223 B. Strings Equalization.cpp ├── 1225 A. Forgetting Things.cpp ├── 1228 A. Distinct Digits.cpp ├── 1230 A. Dawid and Bags of Candies.cpp ├── 1230 B. Ania and Minimizing.cpp ├── 1234 A. Equalize Prices Again.cpp ├── 1236 A. Stones.cpp ├── 1237 A. Balanced Rating Changes.cpp ├── 1238 A Prime Substraction.cpp ├── 1243 A. Maximum Square.cpp ├── 1244 A. Pens and Pencils.cpp ├── 1244 B. Rooms and Staircases.cpp ├── 1249 A. Yet Another Dividing into Teams.cpp ├── 1253 A. Single Push.cpp ├── 1255 A. Changing Volume.cpp ├── 1256 A.Payment Without Change.cpp ├── 1257 A. Two Rival Students.cpp ├── 1257 B. Magic Stick.cpp ├── 1265 A. Beautiful String.cpp ├── 1266 A. Competitive Programmer.cpp ├── 1269 A. Equation.cpp ├── 127 B. Canvas Frames.cpp ├── 1270 A. Card Game.cpp ├── 1271 A. Suits.cpp ├── 1272 A.Three Friends.cpp ├── 1277 A. Happy Birthday, Polycarp!.cpp ├── 1277 B. Make Them Odd.cpp ├── 1278 A. Shuffle Hashing.cpp ├── 1278 B. A and B.cpp ├── 1279 A. New Year Garland.cpp ├── 1281 A. Suffix Three.cpp ├── 1282 A. Temporarily unavailable.cpp ├── 1283 A. Minutes Before the New Year.cpp ├── 1283 B. Candies Division.cpp ├── 1284 A. New Year and Naming.cpp ├── 1285 A. Mezo Playing Zoma.cpp ├── 1287 A. Angry Students.cpp ├── 1291 A. Even But Not Even.cpp ├── 1293 B. JOE is on TV!.cpp ├── 1294 A. Collecting Coins.cpp ├── 1295 Display The Number.cpp ├── 1296 A. Array with Odd Sum.cpp ├── 1296 B. Food Buying.cpp ├── 1300 A. Non-zero.cpp ├── 1300 B. Assigning to Classes.cpp ├── 1301 A. Three Strings.cpp ├── 1303 A.Erasing Zeroes.cpp ├── 1304 A. Two Rabbits.cpp ├── 1305 A. Kuroni and the Gifts.cpp ├── 1307 A. Cow and Haybales.cpp ├── 131 A. cAPS lOCK.cpp ├── 1311 A. Add Odd or Subtract Even.cpp ├── 1312 A. Two Regular Polygons.cpp ├── 1312 B. Bogosort.cpp ├── 1315 A. Dead Pixel.cpp ├── 1316 A. Grade Allocation.cpp ├── 1323 A. Even Subset Sum Problem.cpp ├── 1324 A. Yet Another Tetris Problem.cpp ├── 1324 B. Yet Another Palindrome Problem.cpp ├── 1325 A. EhAb AnD gCd.cpp ├── 1325 B. CopyCopyCopyCopyCopy.cpp ├── 1326 A. Bad Ugly Numbers.cpp ├── 1326 B. Maximums.cpp ├── 1327 Sum of Odd Integers.cpp ├── 1328 A. Divisibility Problem.cpp ├── 133 A. HQ9+.cpp ├── 1331 A. Is it rated.cpp ├── 1331 B. Limericks.cpp ├── 1331 D. Again.cpp ├── 1333 A. Little Artem.cpp ├── 1335 A. Candies and Two Sisters.cpp ├── 1335 B. Construct the String.cpp ├── 1335 C. Two Teams Composing.cpp ├── 1337 A. Ichihime and Triangle.cpp ├── 1337 B. Kana and Dragon Quest game.cpp ├── 1339 A. Filling Diamonds.cpp ├── 1341 A. Nastya and Rice.cpp ├── 1342 A. Road To Zero.cpp ├── 1343 B. Balanced Array.cpp ├── 1345 A. Puzzle Pieces.cpp ├── 1348 A. Phoenix and Balance.cpp ├── 1350 A. Orac and Factors.cpp ├── 1351 B. Square.cpp ├── 1352 A. Sum of Round Numbers.cpp ├── 1353 A. Most Unstable Array.cpp ├── 1353 B. Two Arrays And Swaps.cpp ├── 1358 A. Park Lighting.cpp ├── 1358 B. Maria Breaks the Self-isolation.cpp ├── 136 A.Presents.cpp ├── 1360 A. Minimal Square.cpp ├── 1360 B. Honest Coach.cpp ├── 1360 C. Similar Pairs.cpp ├── 1362 A. Johnny and Ancient Computer.cpp ├── 1363 A. Odd Selection.cpp ├── 1364 A. XXXXX.cpp ├── 1365 B. Trouble Sort.cpp ├── 1365 C. Rotation Matching.cpp ├── 1366 A. Shovels and Swords.cpp ├── 1367 A. Short Substrings.cpp ├── 1367 B. Even Array.cpp ├── 1368 A. C+=.cpp ├── 1369 A. FashionabLee.cpp ├── 1369 B. AccurateLee.cpp ├── 1370 A. Maximum GCD.cpp ├── 1370 B. GCD Compression.cpp ├── 1371 A. Magical Sticks.cpp ├── 1371 B. Magical Calendar.cpp ├── 1372 A. Omkar and Completion.cpp ├── 1373 A. Donut Shops.cpp ├── 1373 B. 01 Game.cpp ├── 1374 A. Required Remainder.cpp ├── 1374 B. Multiply by 2, divide by 6.cpp ├── 1374 C. Move Brackets.cpp ├── 1375 - A. Sign Flipping.cpp ├── 1375 - C. Element Extermination.cpp ├── 1380 A. Three Indices.cpp ├── 1382 A. Common Subsequence.cpp ├── 1385 A. Three Pairwise Maximums.cpp ├── 1385 B. Restore the Permutation by Merger.cpp ├── 1388 A. Captain Flint and Crew Recruitment.cpp ├── 1389 A. LCM Problem.cpp ├── 1391 A. Suborrays.cpp ├── 1391 B. Fix You.cpp ├── 1392 A. Omkar and Password.cpp ├── 1392 B. Omkar and Infinity Clock.cpp ├── 1392 C. Omkar and Waterslide.cpp ├── 1393 A. Rainbow Dash, Fluttershy and Chess Coloring.cpp ├── 1395 A. Boboniu Likes to Color Balls.cpp ├── 1397 A. Juggling Letters.cpp ├── 1397 D. Stoned Game.cpp ├── 1398 A. Bad Triangle.cpp ├── 1398 B. Substring Removal Game.cpp ├── 1399 A. Remove Smallest.cpp ├── 1399 B. Gifts Fixing.cpp ├── 1400 A. String Similarity.cpp ├── 1401 A. Distance and Axis.cpp ├── 1401 B. Ternary Sequence.cpp ├── 1405 A. Permutation Forgery.cpp ├── 1407 A. Ahahahahahahahaha.cpp ├── 1408 A. Circle Coloring.cpp ├── 1409 A. Yet Another Two Integers Problem.cpp ├── 1417 A. Copy-paste.cpp ├── 1418 A. Buying Torches.cpp ├── 1419 D1. Sage's Birthday (easy version).cpp ├── 1420 A. Cubes Sorting.cpp ├── 1421 A. XORwice.cpp ├── 1422 A. Fence.cpp ├── 1426 A. Floor Number.cpp ├── 1427 A. Avoiding Zero.cpp ├── 1428 A. Box is Pull.cpp ├── 1428 C. ABBB.cpp ├── 1430 A. Number of Apartments.cpp ├── 1430 B. Barrels.cpp ├── 1430 C. Numbers on Whiteboard.cpp ├── 1433 A. Boring Apartments.cpp ├── 1433 B. Yet Another Bookshelf.cpp ├── 1433 C. Dominant Piranha.cpp ├── 1435 A. Finding Sasuke.cpp ├── 1436 A. Reorder.cpp ├── 1436 B. Prime Square.cpp ├── 1437 A. Marketing Scheme.cpp ├── 1438 A. Specific Tastes of Andre.cpp ├── 1438 B. Valerii Against Everyone.cpp ├── 1440 A. Buy the String.cpp ├── 1440 B. Sum of Medians.cpp ├── 1443 A. Kids Seating.cpp ├── 1445 A. Array Rearrangment.cpp ├── 1445 B. Elimination.cpp ├── 1447 A. Add Candies.cpp ├── 1447 B. Numbers Box.cpp ├── 1450 A. Avoid Trygub.cpp ├── 1450 B. Balls of Steel.cpp ├── 1451 A. Subtract or Divide.cpp ├── 1451 B. Non-Substring Subsequence.cpp ├── 1452 A. Robot Program.cpp ├── 1452 C. Two Brackets.cpp ├── 1453 A. Cancel the Trains.cpp ├── 1454 A. Special Permutation.cpp ├── 1454 B. Unique Bid Auction.cpp ├── 1455 A. Strange Functions.cpp ├── 1455 B. Jumps.cpp ├── 1457 A. Prison Break.cpp ├── 1459 A. Red-Blue Shuffle.cpp ├── 1461 A. String Generation.cpp ├── 1462 A. Favorite Sequence.cpp ├── 1462 B. Last Year's Substring.cpp ├── 1462 C. Unique Number.cpp ├── 1466 B. Last minute enhancements.cpp ├── 1467 A. Wizard of Orz.cpp ├── 1468 N. Waste Sorting.cpp ├── 1471 A. Strange Partition.cpp ├── 1472 A. Cards for Friends.cpp ├── 1472 B. Fair Division.cpp ├── 1473 A. Replacing Elements.cpp ├── 1474 A. Puzzle From the Future.cpp ├── 1475 A. Odd Divisor.cpp ├── 1475 B. New Year's Number.cpp ├── 1478 A. Nezzar and Colorful Balls.cpp ├── 1480 A. Yet Another String Game.cpp ├── 1486 A. Shifting Stacks.cpp ├── 1487 A. Arena.cpp ├── 1494 A. ABC String.cpp ├── 1499 A. Domino on Windowsill.cpp ├── 1506 A. Strange Table.cpp ├── 158 A. Next Round.cpp ├── 158 B. Taxi.cpp ├── 17 A. Noldbach problem.cpp ├── 182 B. Vasya's Calendar.cpp ├── 195 A. Let's Watch Football.cpp ├── 20 C.Dijkstra.cpp ├── 200 B. Drinks.cpp ├── 22 A. Second Order Statistics.cpp ├── 228 A. Is your horseshoe on the other hoof.cpp ├── 231 A. Team.cpp ├── 234 B. Reading.cpp ├── 236 A. Boy or Girl.cpp ├── 237 A. Free Cash.cpp ├── 245 A. System Administrator.cpp ├── 263 A. Beautiful Matrix.cpp ├── 266 A. Stones on the Table.cpp ├── 281 A. Word Capitalization.cpp ├── 282 A. Bit++.cpp ├── 318 A. Even Odds.cpp ├── 32 A. Reconnaissance.cpp ├── 32 B. Borze.cpp ├── 34 A. Reconnaissance 2.cpp ├── 34 B. Sale.cpp ├── 344 A. Magnets.cpp ├── 379 A. New Year Candles.cpp ├── 38 A. Army.cpp ├── 4 A. Watermelon.cpp ├── 4 C. Registration system.cpp ├── 41 A. Translation.cpp ├── 420 A. Start Up.cpp ├── 43 A. Football.cpp ├── 43 B. Letter.cpp ├── 435 A. Queue on Bus Stop.cpp ├── 44 A. Indian Summer.cpp ├── 443 A. Anton and Letters.cpp ├── 46 A. Ball Game.cpp ├── 467 A. George and Accommodation.cpp ├── 469 A. I Wanna Be the Guy.cpp ├── 47 A. Triangular numbers.cpp ├── 489 B.BerSu Ball.cpp ├── 49 A. Sleuth.cpp ├── 50 A. Domino piling.cpp ├── 509 A. Maximum in Table.cpp ├── 510 A. Fox And Snake.cpp ├── 52 A. 123-sequence.cpp ├── 520 A. Pangram.cpp ├── 545 D. Queue.cpp ├── 546 A. Soldier and Bananas.cpp ├── 550 A. Two Substrings.cpp ├── 572 A. Arrays.cpp ├── 58 A. Chat room.cpp ├── 58 B. Coins.cpp ├── 580 A. Kefa and First Steps.cpp ├── 581 A. Vasya the Hipster.cpp ├── 59 A. Word.cpp ├── 599 A. Patrick and Shopping.cpp ├── 6 A. Triangle.cpp ├── 609 A. USB Flash Drives.cpp ├── 61 A. Ultra-Fast Mathematician.cpp ├── 617 A. Elephant.cpp ├── 622 A. Infinite Sequence.cpp ├── 622 B. The Time.cpp ├── 652 B. z-sort.cpp ├── 658 A. Bear and Reverse Radewoosh.cpp ├── 672 A. Summer Camp.cpp ├── 672 B. Different is Good.cpp ├── 677 A. Vanya and Fence.cpp ├── 69 A. Young Physicist.cpp ├── 701 A. Cards.cpp ├── 703 A. Mishka and Game.cpp ├── 705 A. Hulk.cpp ├── 71 A. Way Too Long Words.cpp ├── 711 A. Bus to Udayland.cpp ├── 716 A. Crazy Computer.cpp ├── 734 A. Anton and Danik.cpp ├── 74 A. Room Leader.cpp ├── 746 A. Compote.cpp ├── 749 A. Bachgold Problem.cpp ├── 75 A. Life Without Zeros.cpp ├── 750 A. New Year and Hurry.cpp ├── 758 A. Holiday Of Equality.cpp ├── 766 A. Mahmoud and Longest Uncommon Subsequence.cpp ├── 776 A. A Serial Killer.cpp ├── 777 A. Shell Game.cpp ├── 78 A. Haiku.cpp ├── 78 B. Easter Eggs.cpp ├── 785 A. Anton and Polyhedrons.cpp ├── 791 A. Bear and Big Brother.cpp ├── 798 A. Mike and palindrome.cpp ├── 80 A. Panoramix's Prediction.cpp ├── 805 A. Fake NP.cpp ├── 805 B. 3-palindrome.cpp ├── 807 A. Is it rated.cpp ├── 808 A. Lucky Year.cpp ├── 810 A. Straight «A».cpp ├── 814 A. An abandoned sentiment from past.cpp ├── 820 A. Mister B and Book Reading.cpp ├── 822 A. I'm bored with life.cpp ├── 834 A. The Useless Toy.cpp ├── 839 A. Arya and Bran.cpp ├── 841 A. Generous Kefa.cpp ├── 841 B. Godsend.cpp ├── 844 A. Diversity.cpp ├── 847 G. University Classes.cpp ├── 854 A. Fraction.cpp ├── 855 A. Tom Riddle's Diary.cpp ├── 864 A. Fair Game.cpp ├── 864 B. Polycarp and Letters.cpp ├── 867 A. Between the Offices.cpp ├── 868 A. Bark to Unlock.cpp ├── 870 A. Search for Pretty Integers.cpp ├── 884 A. Book Reading.cpp ├── 887 A. Div. 64.cpp ├── 893 A. Chess For Three.cpp ├── 893 B. Beautiful Divisors.cpp ├── 897 A. Scarborough Fair.cpp ├── 898 A. Rounding.cpp ├── 899 A. Splitting in Teams.cpp ├── 9 A. Die Roll.cpp ├── 903 A. Hungry Student Problem.cpp ├── 903 C. Boxes Packing.cpp ├── 909 A. Generate Login.cpp ├── 913 A. Modular Exponentiation.cpp ├── 914 A. Perfect Squares.cpp ├── 915 A. Garden.cpp ├── 918 A. Eleven.cpp ├── 918 B. Radio Station.cpp ├── 931 A. Friends Meeting.cpp ├── 935 A. Fafa and his Company.cpp ├── 939 A. Love Triangle.cpp ├── 939 B. Hamster Farm.cpp ├── 959 A. Mahmoud and Ehab and the even-odd game.cpp ├── 96 A. Football.cpp ├── 976 A. Minimum Binary Number.cpp ├── 977 A. Wrong Subtraction.cpp ├── 977 B. Two-gram.cpp ├── 978 A. Remove Duplicates.cpp ├── 978 B. File Name.cpp ├── 980 A. Links and Pearls.cpp ├── 981 A. Antipalindrome.cpp ├── 981 B. Businessmen Problems.cpp ├── 984 A. Game.cpp ├── 987 A. Infinity Gauntlet.cpp ├── 987 B. High School, Become Human.cpp ├── 988 A. Diverse Team.cpp ├── 991 A. If at first you don't succeed....cpp ├── 991 B. Getting an A.cpp ├── 992 A. Nastya and an Array.cpp ├── 994 A. Fingerprints.cpp ├── 996 A. Hit the Lottery.cpp ├── 998 A. Balloons.cpp ├── 999 A. Mishka and Contest.cpp └── README.md /1 A. Theatre Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,m,a,ans; 6 | cin>>n>>m>>a; 7 | ans=((n+a-1)/a)*((m+a-1)/a); 8 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int l1,l2,len,c=0; 6 | string s,t; 7 | cin>>s>>t; 8 | l1=s.length(); 9 | l2=t.length(); 10 | len=l1+l2; 11 | // cout<=0 && l2>=0){ 20 | if(s[l1] == t[l2]){ 21 | c++; 22 | l1--,l2--; 23 | } 24 | else if( (s[l1] != t[l2]) || (l1==-1 || l2==-1) ){ 25 | break; 26 | } 27 | } 28 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n; 11 | ll a[1010]; 12 | cin>>n; 13 | for(int i=0; i>a[i]; 15 | if(a[i] % 2 == 0){ 16 | a[i] = a[i]-1; 17 | } 18 | } 19 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i=0; 6 | int a,b,c,d; 7 | int s[1001]; 8 | cin>>n; 9 | for(i=0; i>a>>b>>c>>d; 12 | sum=a+b+c+d; 13 | s[i]=sum; 14 | } 15 | // for(i=0; i()); 20 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,tag=0; 6 | // all comments are bug 7 | // string s; 8 | cin>>n; 9 | int s[105]; 10 | // cin>>s; 11 | for(int i=0; i>s[i]; 14 | tag+=s[i]; 15 | // if(s[i]==1) 16 | // { 17 | // tag=1; 18 | // break; 19 | // } 20 | } 21 | // if(tag==1) 22 | if(tag>0) 23 | cout<<"HARD"; 24 | else 25 | cout<<"EASY"; 26 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,a,b,c; 12 | cin>>n; 13 | if( (n - 2) % 3 == 0){ 14 | a = 1,b = 2,c = (n - 3); 15 | } 16 | else{ 17 | a = 1,b = 1,c = (n - 2); 18 | } 19 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int n,eights=0; 9 | string s; 10 | cin>>n>>s; 11 | for(int i=0; i= n/11){ 17 | cout< 11){ 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int n, s, ans = 0; 9 | cin>>n>>s; 10 | for(int i=n; i>0; i--){ 11 | ans+=s/i; 12 | s%=i; 13 | } 14 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | ll s,a,b,c; 12 | ull ans,can_buy,div; 13 | 14 | cin>>t; 15 | while(t--) 16 | { 17 | div = can_buy = ans = 0; 18 | cin>>s>>a>>b>>c; 19 | can_buy = s/c; 20 | div = can_buy/a; 21 | ans = (div*a) + (div*b); 22 | ans +=(can_buy%a); 23 | 24 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long long int a,b,q,d; 7 | long long int ans; 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | ans=d=0; 13 | cin>>a>>b>>q; 14 | if(q%2==1){ 15 | d=(q/2)+1; 16 | }else{ 17 | d=q/2; 18 | } 19 | ans=(d*a)-((q-d)*b); 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n,a[101]; 11 | cin>>n; 12 | for(int i=0; i>a[i]; 14 | } 15 | int k = 0; 16 | for(int i=1; i 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,k,sum; 6 | cin>>n>>k; 7 | long int red,green,blue; 8 | red=ceil( ( ( 2 * n ) + k - 1 ) / k ); 9 | green=ceil( ( ( 5 * n ) + k - 1 ) / k ); 10 | blue=ceil( ( ( 8 * n ) + k - 1 ) / k ); 11 | sum=red+green+blue; 12 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int n; 9 | cin>>n; 10 | if(n == 2){ 11 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n,a,b; 11 | 12 | int ans1 = 0, ans2 = 0, flag = 0; 13 | 14 | cin>>n; 15 | if(n < 2){ 16 | cout<<-1< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | fastread(); 11 | ll n,k,a; 12 | cin>>n>>k; 13 | sets; 14 | s.insert(0); 15 | for(ll i=0; i>a; 17 | s.insert(a); 18 | } 19 | 20 | auto it = s.begin(); 21 | for(auto i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n,k; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n>>k; 15 | char a[] = {"abcdefghijklmnopqrstuvwxyz"}; 16 | int j = 0; 17 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,s=0,i; 6 | cin>>n; 7 | int a[n+5]; 8 | for(i=0; i>a[i]; 10 | sort(a,a+n); 11 | for(i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n; 6 | cin>>t; 7 | while(t--){ 8 | int ans=0; 9 | cin>>n; 10 | // for(int i=7; i>1; i--){ 11 | // ans+=n/i; 12 | // n=n%i; 13 | // } 14 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | string s,r; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>s; 12 | r=s; 13 | reverse(r.begin(),r.end()); 14 | int len=s.length(); 15 | int tag=0; 16 | setS; 17 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,k = 3; 12 | string s,t; 13 | cin>>n>>s; 14 | if(n >= 2){ 15 | t += s[0]; 16 | t += s[1]; 17 | } 18 | else{ 19 | t += s[0]; 20 | } 21 | for(int i=3; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n; 12 | cin>>n; 13 | vectora(n); 14 | for(ll i=0; i>a[i]; 16 | } 17 | sort(a.begin(),a.end()); 18 | ll ans = a[n-2] - a[0]; 19 | ans = min(ans,(a[n-1] - a[1]) ); 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll l,r; 13 | cin>>t; 14 | while(t--){ 15 | cin>>l>>r; 16 | 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | int n=5,tag=0; 8 | while(n--) 9 | { 10 | string t; 11 | cin>>t; 12 | //bug if(s[0]=='A' && t[0]=='A') 13 | if(s[0]==t[0]) 14 | tag=1; 15 | else if(s[1]==t[1]) 16 | tag=1; 17 | } 18 | if(tag==1) 19 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | char s[100]; 6 | int i,cn=0,ln; 7 | scanf("%s",&s); 8 | ln=strlen(s); 9 | for(i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | 12 | ll t,l,r,d; 13 | cin>>t; 14 | while(t--){ 15 | ll ans = 0, div = 0; 16 | cin>>l>>r>>d; 17 | if(d < l){ 18 | ans = d; 19 | } 20 | else if(d <= r){ 21 | div = r /d; 22 | div++; 23 | ans = (d * div); 24 | } 25 | else if(d > r){ 26 | ans = d; 27 | } 28 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n; 12 | cin>>n; 13 | n %= 4; 14 | if(n == 0 || n == 3){ 15 | cout<<0< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | cin>>n; 13 | 14 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | typedef long long LL; 9 | int n,a[300001],b[300001]; 10 | LL sum = 0,temp = 0; 11 | int main() 12 | { 13 | fastread(); 14 | scanf("%d", &n); 15 | for(int i=0; i()); 21 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll L,R,l,r; 13 | cin>>t; 14 | while(t--){ 15 | cin>>L>>R>>l>>r; 16 | if(R == r){ 17 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int t,a,b; 9 | cin>>t; 10 | while(t--) 11 | { 12 | ll n,ans = 0; 13 | cin>>n>>a>>b; 14 | if(a * 2 < b){ 15 | ans = n * a; 16 | } 17 | else{ 18 | ll mod = n % 2; 19 | ans = (n / 2) * b + (mod * a); 20 | } 21 | cout< 2 | using namespace std; 3 | const int MXN = 5e5 + 30; 4 | int ans=0; 5 | int a[MXN],b[MXN]; 6 | int main() 7 | { 8 | int n,m,k; 9 | int i,j,x; 10 | cin>>n>>m>>k; 11 | for(i=1; i<=n; i++) 12 | cin>>a[i]; 13 | for(i=1; i<=n; i++) 14 | cin>>b[i]; 15 | 16 | for(i=1; i<=k; i++) 17 | { 18 | cin>>x; 19 | for(j=1; j<=n; j++) 20 | { 21 | if(b[j]==b[x] && a[j]>a[x]) 22 | { 23 | ans++; 24 | break; 25 | } 26 | } 27 | } 28 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | int n,a[1001],positive=0,negative=0; 7 | cin>>n; 8 | 9 | int div=0; 10 | if(n%2 == 0){ 11 | div = n/2; 12 | } 13 | else if( n%2 != 0){ 14 | div = (n/2)+1; 15 | } 16 | 17 | for(int i=0; i>a[i]; 19 | if( a[i] > 0){ 20 | positive++; 21 | } 22 | else if( a[i] < 0 ){ 23 | negative++; 24 | } 25 | } 26 | 27 | if( div <= positive ){ 28 | cout<<1<<"\n"; 29 | } 30 | else if( div <= negative){ 31 | cout<<-1<<"\n"; 32 | } 33 | else{ 34 | cout<<0<<"\n"; 35 | } 36 | return 0; 37 | } 38 | 39 | /* 40 | SIMPLE INPUT 41 | 5 42 | 10 0 -7 2 6 43 | */ 44 | -------------------------------------------------------------------------------- /1136 A. Nastya Is Reading a Book.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,k,page=0; 6 | int finish[10000]; 7 | finish[0]=0; 8 | cin>>n; 9 | for(int i=1; i<=n; i++){ 10 | int s,f; 11 | cin>>s>>f; 12 | finish[i]=f; 13 | } 14 | cin>>k; 15 | for(int i=1; i<=n; i++){ 16 | if(k<=finish[i]){ 17 | page=i; 18 | break; 19 | } 20 | } 21 | if(page==1){ 22 | cout<1){ 25 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,m,ans = 0; 12 | cin>>n>>m; 13 | 14 | if(n == m){ 15 | cout<<0< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,rest = 0,ans = 0; 12 | cin>>n; 13 | vectora(n); 14 | for(int i=0; i>a[i]; 16 | } 17 | for(int i=0; i<2*n; i++){ 18 | if(a[i%n] == 1){ 19 | rest++; 20 | ans = max(ans,rest); 21 | } 22 | else{ 23 | rest = 0; 24 | } 25 | } 26 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int len=0,As=0,good=0; 6 | string s; 7 | cin>>s; 8 | len=s.length(); 9 | for(int i=0; iAs) 19 | // cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll a,b,c,ans = 0; 12 | cin>>a>>b>>c; 13 | ans += min(a,b); 14 | ans *= 2; 15 | ll Min = min(a,b); 16 | if(a > Min){ 17 | ans++; 18 | } 19 | else if(b > Min){ 20 | ans++; 21 | } 22 | ans += c * 2; 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int ans=0,n,c=0,i; 6 | cin>>n; 7 | int a[n+9]; 8 | for(i=1; i<=n; i++) 9 | cin>>a[i]; 10 | for(i=1; i<=n; i++) 11 | { 12 | c=0; 13 | int x=a[i]; 14 | while(x != -1) 15 | { 16 | x=a[x]; 17 | c++; 18 | } 19 | ans=max(ans, c); 20 | } 21 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,t,s,d; 12 | cin>>n>>t; 13 | pair v ={1e9, -1}; 14 | for(int i=1; i<=n; i++){ 15 | cin>>s>>d; 16 | while(s < t){ 17 | s += d; 18 | } 19 | v = min(pair< int,int>(s,i),v); 20 | } 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int a[5]; 6 | for(int i=0; i<4; i++) 7 | cin>>a[i]; 8 | 9 | sort(a,a+4); 10 | for(int i=0; i<3; i++) 11 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,have = 0;; 12 | string s; 13 | cin>>n>>s; 14 | //reverse(s.begin(),s.end()); 15 | for(int i=0; i 0){ 17 | have--; 18 | } 19 | else if(s[i] == '+'){ 20 | have++; 21 | } 22 | } 23 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n,h,m; 11 | ll l,r,x; 12 | cin>>n>>h>>m; 13 | ll a[n+1]; 14 | for(int i=1; i<=n; i++){ 15 | a[i] = h; 16 | } 17 | for(int i=0; i>l>>r>>x; 19 | 20 | for(int j=l; j<=r; j++){ 21 | if(x < a[j]){ 22 | a[j] = x; 23 | } 24 | } 25 | } 26 | ll sum = 0; 27 | for(int i=1; i<=n; i++){ 28 | sum += (a[i] * a[i]); 29 | } 30 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,m; 12 | cin>>n>>m; 13 | int sub = 0,ans = 0; 14 | sub = n - m; 15 | if(m == 0){ 16 | ans = 1; 17 | } 18 | else if(n == m){ 19 | ans = 0; 20 | } 21 | else{ 22 | ans = min(sub,m); 23 | } 24 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,a[200001]; 12 | cin>>n; 13 | for(ll i=0; i>a[i]; 15 | sort(a,a+n); 16 | ll k = 1,ans = 0; 17 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,tag; 6 | cin>>t; 7 | while(t--) 8 | { 9 | tag=0; 10 | string s; 11 | cin>>n>>s; 12 | for(int i=0; i=11) 16 | { 17 | tag=1; 18 | break; 19 | } 20 | } 21 | //cout<=11) 23 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,c; 6 | cin>>a>>b>>c; 7 | 8 | if(!a && !b && !c) 9 | { 10 | cout << 0; 11 | return 0; 12 | } 13 | if(!c && a == b) 14 | { 15 | cout << 0; 16 | return 0; 17 | } 18 | if(a > b + c) 19 | cout << '+'; 20 | else 21 | { 22 | if(b > a+c) 23 | cout << '-'; 24 | else 25 | cout << '?'; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1174 A. Ehab Fails to Be Thanos.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,a[2002]; 12 | cin>>n; 13 | n *= 2; 14 | sets; 15 | for(int i=0; i>a[i]; 17 | s.insert(a[i]); 18 | } 19 | sort(a,a+n); 20 | if( s.size() == 1){ 21 | cout<<-1; 22 | } 23 | else{ 24 | for(int i=0; i 3 | using namespace std; 4 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 5 | 6 | unsigned long long n,k,ans; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | ans=0; 15 | cin>>n>>k; 16 | while(n>0) 17 | { 18 | if(n%k == 0){ 19 | n/=k; 20 | ans++; 21 | } 22 | else if(n%k != 0){ 23 | long long over = n % k; 24 | n-=over; 25 | ans+=over; 26 | } 27 | if(n==0){ 28 | break; 29 | } 30 | // cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll n; 14 | string s,t; 15 | cin>>s; 16 | n = s.length(); 17 | transform(s.begin(),s.end(),s.begin(), ::tolower); 18 | 19 | for(ll i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | cin>>n; 13 | int sum = 0,temp = 0,noneed = 0,j = 1; 14 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | ll a[10000001]; 9 | int main() 10 | { 11 | fastread(); 12 | int t; 13 | ll n,k; 14 | cin>>t; 15 | while(t--){ 16 | cin>>n>>k; 17 | for(int i=0; i>a[i]; 19 | } 20 | sort(a,a+n); 21 | ll tk = a[0]+k; 22 | if(abs(tk - a[0]) <= k && abs(tk - a[n-1]) <= k){ 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,k; 6 | cin>>n>>m>>k; 7 | if(n<=m && n<=k) 8 | cout<<"Yes"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int T; 12 | ll n,s,t; 13 | cin>>T; 14 | while(T--){ 15 | cin>>n>>s>>t; 16 | ll ans = max(n-s,n-t); 17 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | string s; 13 | cin>>n>>s; 14 | int zero = 0,one = 0; 15 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | if(n%4==1) 8 | cout<<0<<" "<<"A"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll n ,x; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n>>x; 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | long long int a,b,c; 8 | long long int ans; 9 | while(t--) 10 | { 11 | ans=0; 12 | cin>>a>>b>>c; 13 | ans=(a+b+c)/2; 14 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int n,sum=0; 9 | string s; 10 | cin>>s; 11 | n = s.length(); 12 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,a[250],b[250]; 6 | cin>>n; 7 | for(int i=0; i>a[i]; 9 | } 10 | cin>>m; 11 | for(int i=0; i>b[i]; 13 | } 14 | sort(a,a+n,greater()); 15 | sort(b,b+m,greater()); 16 | 17 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t; 12 | cin>>t; 13 | while(t--){ 14 | ll a,b,n,xr = 0; 15 | cin>>a>>b>>n; 16 | vectorv; 17 | xr = a ^ b; 18 | v.pb(a),v.pb(b),v.pb(xr); 19 | if(n % 3 == 0){ 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | ll a,coin = 0,odd = 0; 13 | cin>>n; 14 | for(int i=0; i>a; 16 | if(a % 2 == 1){ 17 | odd++; 18 | } 19 | } 20 | coin = min(odd,n-odd); 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a1,a2,k1,k2; 6 | cin>>a1>>a2>>k1>>k2>>n; 7 | if(k1>k2) 8 | { 9 | swap(k1,k2); 10 | swap(a1,a2); 11 | } 12 | int x; 13 | if(n<=a1*k1) 14 | x=n/k1; 15 | else 16 | x=a1+(n-a1*k1)/k2; 17 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,ans = 0; 12 | cin>>n; 13 | string s; 14 | cin>>s; 15 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int n,a[1001],b[1001],ans = 0; 9 | cin>>n; 10 | for(int i=0; i>a[i]; 12 | b[i] = a[i]; 13 | } 14 | sort(b,b+n,greater()); 15 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i; 6 | string s; 7 | cin>>n; 8 | int one[n]; 9 | int zero[n]; 10 | memset(one,-1,sizeof(one)); 11 | memset(zero,-1,sizeof(zero)); 12 | 13 | cin>>s; 14 | for(i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | long long int n; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n; 11 | if(n==2) 12 | { 13 | cout<<2< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int A,B; 12 | ll a,b; 13 | cin>>A>>B; 14 | if(A == B){ 15 | a = A*10; 16 | b = a; 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int l,r,c,i; 6 | cin>>l>>r; 7 | for(i=l; i<=r; i++) 8 | { 9 | string b=to_string(i); 10 | c=0; 11 | for(int j=0; j 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,c,d; 6 | cin>>a>>b>>c>>d; 7 | if(a==b+c+d || b==a+c+d || c==a+b+d || d==a+b+c || a+b==c+d || a+c==b+d || a+d==b+c) 8 | { 9 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,k,i,j; 7 | cin>>n>>k; 8 | char arr[n+5]; 9 | cin>>arr; 10 | if(k==0) 11 | { 12 | cout<=1) 16 | { 17 | cout<<"0"; 18 | return 0; 19 | } 20 | if(arr[0]!='1') 21 | { 22 | j=1; 23 | arr[0]='1'; 24 | } 25 | else 26 | j=0; 27 | for(i=1; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,a,sum=0,ans=0; 6 | int avg; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n; 11 | for(int i=0; i>a; 14 | sum+=a; 15 | } 16 | avg=sum/n; 17 | if((avg*n)>=sum) 18 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,a,b,c; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int s=0; 10 | cin>>a>>b>>c; 11 | while(b>=1 && c>=2) 12 | { 13 | s+=3; 14 | b=b-1; 15 | c=c-2; 16 | } 17 | while(b>=2 && a>=1) 18 | { 19 | s+=3; 20 | b=b-2; 21 | a=a-1; 22 | } 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | int a[n]; 8 | for(int i=0; i>a[i]; 10 | int flag=0; 11 | for(int j=0; j 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | 7 | long long a,b; 8 | cin>>a>>b; 9 | if((a-b)>1) 10 | cout<<"YES\n"; 11 | else 12 | cout<<"NO\n"; 13 | 14 | } 15 | int main() 16 | { 17 | 18 | int t; 19 | t=1; 20 | cin>>t; 21 | while(t--) 22 | { 23 | solve(); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /1243 A. Maximum Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define Copy_maris_nah int main() 3 | #define Okay_bye return 0 4 | 5 | using namespace std; 6 | Copy_maris_nah 7 | { 8 | int t,n; 9 | int ans; 10 | cin>>t; 11 | while(t--) 12 | { 13 | ans=1; 14 | cin>>n; 15 | int a[n+5]; 16 | for(int i=0; i>a[i]; 18 | sort(a,a+n); 19 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int a,b,c,d,k; 7 | int x,y; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>a>>b>>c>>d>>k; 12 | if(a%c==0) 13 | x=a/c; 14 | if(a%c!=0) 15 | x=a/c+1; 16 | if(b%d==0) 17 | y=b/d; 18 | if(b%d!=0) 19 | y=b/d+1; 20 | if((x+y)>k) 21 | cout<<"-1"< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int a,b,c; 6 | int ans=0; 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>a>>b; 12 | c=abs(a-b); 13 | ans=c/5; 14 | c=c%5; 15 | if(c==1 or c==2)ans++; 16 | else if(c)ans+=2; 17 | 18 | cout< 2 | #define Copy_maris_nah int main() 3 | #define Okay_bye return 0 4 | using namespace std; 5 | 6 | Copy_maris_nah 7 | { 8 | int t; 9 | long long int a,b,n,s,sum; 10 | cin>>t; 11 | while(t--) 12 | { 13 | sum=0; 14 | cin>>a>>b>>n>>s; 15 | 16 | long long int d = s / n; 17 | d = min(d, a); 18 | 19 | if (s - n * d <= b) { 20 | cout << "YES" << endl; 21 | } else { 22 | cout << "NO" << endl; 23 | } 24 | } 25 | Okay_bye; 26 | } 27 | -------------------------------------------------------------------------------- /1257 A. Two Rival Students.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | int n,Xswap,posA,posB; 8 | while(t--) 9 | { 10 | cin>>n>>Xswap>>posA>>posB; 11 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | cin>>t; 12 | 13 | ll x,y; 14 | while(t--) 15 | { 16 | cin>>x>>y; 17 | if(x == 1 && y > 1){ 18 | cout<<"NO"< 3){ 22 | cout<<"NO"< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n; 6 | cin>>n; 7 | if(n==1) 8 | cout<<9<<" "<<8< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,f,s,k,x,y; 6 | cin>>t; 7 | while(t--) 8 | { 9 | x=y=0; 10 | cin>>n>>f>>s; 11 | for(int i=0; i>k; 14 | x=max(x,k); 15 | } 16 | for(int i=0; i>k; 19 | y=max(y,k); 20 | } 21 | if(x>y) 22 | cout<<"YES"< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | int a[5]; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>a[0]>>a[1]>>a[2]; 12 | sort(a,a+3); 13 | int ans= 2*(a[2]-a[0]-2); 14 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,tag,lenP,lenH,i; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string p,h; 10 | tag=0; 11 | cin>>p>>h; 12 | lenP=p.size(); 13 | lenH=h.size(); 14 | if(lenP>lenH) 15 | { 16 | cout<<"NO"< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int t,a,b,d,sum; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>a>>b; 10 | d=abs(a-b); 11 | sum=0; 12 | for(long long int i=0; i<100000; i++) 13 | { 14 | sum+=i; 15 | if(sum>=d && (sum-d)%2==0) 16 | { 17 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | int t; 10 | long long int a[4]; 11 | cin>>t; 12 | while(t--) 13 | { 14 | cin>>a[0]>>a[1]>>a[2]; 15 | sort(a,a+3); 16 | if(a[0]+a[1] 2 | using namespace std; 3 | int main() 4 | { 5 | int t,len; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string s; 10 | len=0; 11 | cin>>s; 12 | len=s.size(); 13 | if(s[len-1]=='o' && s[len-2]=='p') 14 | cout<<"FILIPINO"< 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,c,r,t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>a>>b>>c>>r; 10 | if(a>b) 11 | swap(a,b); 12 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int h,m,t,day,time; 6 | cin>>t; 7 | while(t--) 8 | { 9 | time=0; 10 | cin>>h>>m; 11 | day=24*60; 12 | time=h*60+m; 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int t,n,k,a; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>n>>k; 10 | if(n%k==0) 11 | cout<>s; 15 | for(int i=0; i 3 | using namespace std; 4 | int main() 5 | { 6 | int n; 7 | cin>>n; 8 | double m = n; 9 | double ans = 0; 10 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | long long int t,a,b,c,n,sum; 9 | cin>>t; 10 | while(t--) 11 | { 12 | sum=0; 13 | cin>>a>>b>>c>>n; 14 | sum+=a+b+c+n; 15 | if(sum%3!=0 || sum/3 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string str=" "; 10 | cin>>n; 11 | while(n>=4) 12 | str+="1",n-=2; 13 | if(n==3) 14 | str+="7",n-=3; 15 | else if(n==2) 16 | str+="1",n-=2; 17 | reverse(str.begin(),str.end()); 18 | 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n; 6 | cin>>t; 7 | int odd,even; 8 | int a[10000]; 9 | while(t--) 10 | { 11 | odd=even=0; 12 | cin>>n; 13 | for(int i=0; i>a[i]; 16 | if(a[i]%2==0) 17 | even++; 18 | else 19 | odd++; 20 | } 21 | if (odd & 1 or (odd > 0 and even > 0)) 22 | cout<<"YES"< 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | long long int n,ans,div; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | ans=n,div=0; 13 | if(n<10){ 14 | cout<=10){ 20 | div=n/10; 21 | n=n%10; 22 | n=n+div; 23 | ans+=div; 24 | } 25 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,a[1000]; 6 | int sum,zero; 7 | cin>>t; 8 | while(t--) 9 | { 10 | sum=zero=0; 11 | cin>>n; 12 | for(int i=0; i>a[i]; 15 | if(a[i]==0)zero++; 16 | sum+=a[i]; 17 | 18 | } 19 | int ans=zero; 20 | sum+=zero; 21 | if(sum==0) 22 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll t,n,a; 14 | cin>>t; 15 | while(t--){ 16 | cin>>n; 17 | ll idx = n; 18 | n = n * 2; 19 | 20 | vectorv; 21 | for(ll i=0; i>a; 23 | v.pb(a); 24 | } 25 | sort(v.begin(),v.end()); 26 | 27 | ll ans = 0; 28 | ans = abs(v[idx-1]- v[idx]); 29 | 30 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | 8 | long long int x,y,z,a,b,c; 9 | while(t--) 10 | { 11 | cin>>x>>y>>a>>b; 12 | z=y-x; 13 | c=a+b; 14 | if(z%c==0) 15 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | long long int a,b,ans,dis; 7 | cin>>t; 8 | while(t--){ 9 | ans=dis=0; 10 | cin>>a>>b; 11 | if(a == b){ 12 | cout<<0<<"\n"; 13 | continue; 14 | } 15 | if(a>b){ 16 | dis=a - b; 17 | ans++; 18 | if(dis % 2 !=0){ 19 | ans++; 20 | } 21 | } 22 | else if(a < b){ 23 | dis= b - a; 24 | ans++; 25 | if(dis % 2 != 1){ 26 | ans++; 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,m,n; 6 | int tag; 7 | cin>>t; 8 | while(t--) 9 | { 10 | tag=0; 11 | cin>>n>>m; 12 | if(n%m==0) 13 | cout<<"YES\n"; 14 | else 15 | cout<<"NO\n"; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /1312 B. Bogosort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a[105]; 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n; 11 | for(int i=0; i>a[i]; 13 | sort(a,a+n,greater()); 14 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll a,b,x,y; 13 | cin>>t; 14 | while(t--){ 15 | cin>>a>>b>>x>>y; 16 | 17 | ll ans,ans1,ans2,ans3,ans4; 18 | ans = ans1 = ans2 = ans3 = ans4 = 0; 19 | ans1 = a * y; 20 | ans2 = b * x; 21 | ans3 = (a - 1 - x) * b; 22 | ans4 = a * (b - 1 - y); 23 | 24 | ans = max(ans1,ans2); 25 | ans = max(ans,max(ans3,ans4)); 26 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int n,a[105],tag; 7 | cin>>t; 8 | while(t--) 9 | { 10 | tag=0; 11 | cin>>n; 12 | for(int i=1;i<=n;i++){ 13 | cin>>a[i]; 14 | } 15 | if(n==1&&a[1]%2==1) 16 | cout<<-1< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int n,a[1000]; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int even=0,odd=0; 11 | cin>>n; 12 | 13 | for(int i=0; i>a[i]; 15 | } 16 | for(int i=0; i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | long long n; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | int a=0,b=0; 13 | if(n%2==0) 14 | { 15 | a=n/2; 16 | b=n/2; 17 | } 18 | else{ 19 | a=n-1; 20 | b=1; 21 | } 22 | 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int a,b; 10 | cin>>a; 11 | sets; 12 | while(a--) 13 | { 14 | int b; 15 | cin>>b; 16 | s.insert(b); 17 | } 18 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>n; 10 | if(n==1) 11 | cout<<-1< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll n, m = 0, a; 12 | cin>>n; 13 | for(ll i=0; i>a; 15 | if(i == 0){ 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n,k; 11 | cin>>t; 12 | while(t--) 13 | { 14 | cin>>n>>k; 15 | if(k*k > n){ 16 | cout<<"NO"< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | long long int a,b; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int div=0,pls=0; 11 | cin>>a>>b; 12 | if(a%b==0){ 13 | cout<<0< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | int tag=0; 8 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | cout<<"No"< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | for(int i=2; i<=n; i++){ 8 | while(n%i==0){ 9 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | int l; 8 | l=s.length(); 9 | if(s[l-1]%2==0) 10 | cout<<0< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int n,m; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n>>m; 11 | char a[101][101]; 12 | a[0][0]='a'; 13 | for(int i=1; i<=n; i++){ 14 | for(int j=1; j<=m; j++){ 15 | if(i==1 && j==1) 16 | a[i][j]='W'; 17 | else 18 | a[i][j]='B'; 19 | } 20 | } 21 | for(int i=1; i<=n; i++){ 22 | for(int j=1; j<=m; j++){ 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | double n; 7 | long long int ans; 8 | cin>>t; 9 | while(t--){ 10 | ans=0; 11 | cin>>n; 12 | ans=ceil((n/2)-1); 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int n,a,b; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n>>a>>b; 11 | char c[]="abcdefghijklmnopqrstuvwxyz"; 12 | string s; 13 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | long long int a,b,c,d; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>a>>b>>c>>d; 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | long long int n; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n; 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int n,a,b,c,d; 7 | int ABsum,ABsub,CDsum,CDsub; 8 | cin>>t; 9 | while(t--) 10 | { 11 | ABsum=ABsub=CDsum=CDsub=0; 12 | cin>>n>>a>>b>>c>>d; 13 | ABsum=a+b; 14 | ABsub=a-b; 15 | 16 | CDsum=c+d; 17 | CDsub=c-d; 18 | 19 | if( (n*ABsum >= CDsub) && (n*ABsub <= CDsum) ){ 20 | cout<<"YES\n"; 21 | } 22 | else{ 23 | cout<<"NO\n"; 24 | } 25 | } 26 | return 0; 27 | } 28 | /* 29 | SIMPLE INPUT 30 | 5 31 | 7 20 3 101 18 32 | 11 11 10 234 2 33 | 8 9 7 250 122 34 | 19 41 21 321 10 35 | 3 10 8 6 1 36 | */ 37 | -------------------------------------------------------------------------------- /1342 A. Road To Zero.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll x,y,a,b; 13 | cin>>t; 14 | while(t--){ 15 | cin>>x>>y>>a>>b; 16 | 17 | if(x > y){ 18 | swap(x,y); 19 | } 20 | ll ans1 = 0, ans2 = 0; 21 | ans1 = x*a + y*a; 22 | ll z = y - x; 23 | ans2 = z*a + x * b; 24 | 25 | cout< 2 | using namespace std; 3 | long long int a[1000000]; 4 | int main() 5 | { 6 | int t; 7 | long long int n,sum1,sum2,d,i,j; 8 | cin>>t; 9 | while(t--) 10 | { 11 | sum1=sum2=0; 12 | cin>>n; 13 | 14 | if(n%4!=0){ 15 | cout<<"NO\n"; 16 | } 17 | else{ 18 | cout<<"YES\n"; 19 | for(int i=2; i<=n; i+=2){ 20 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | int t,n,m; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>n>>m; 11 | if( (n==1) || (m == 1) || (n*m == 4)){ 12 | cout<<"YES\n"; 13 | } 14 | else{ 15 | cout<<"NO\n"; 16 | } 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /1351 B. Square.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long long int t,a,a1,b,b1; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>a>>b>>a1>>b1; 11 | if(a > b)swap(a,b); 12 | if(a1 > b1)swap(a1,b1); 13 | 14 | if(a+a1 == b && a+a1 == b1){ 15 | cout<<"YES\n"; 16 | } 17 | else{ 18 | cout<<"NO\n"; 19 | } 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /1353 A. Most Unstable Array.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | long long int n,m; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n>>m; 12 | if(n == 1 ){ 13 | cout<<0<2){ 21 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | int t,n,k; 7 | int a[101],b[101]; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n>>k; 12 | for(int i=0; i>a[i]; 14 | } 15 | for(int i=0; i>b[i]; 17 | } 18 | sort(a,a+n); 19 | sort(b,b+n,greater()); 20 | for(int i=0; i a[j]){ 23 | swap(a[j],b[j]); 24 | break; 25 | } 26 | } 27 | } 28 | int sum=0; 29 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int t,n,m; 9 | cin>>t; 10 | while(t--){ 11 | double A,B; 12 | cin>>n>>m; 13 | A = n, B = m; 14 | ll ans = 0; 15 | ans = ceil((A*B) / 2); 16 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int t,n; 9 | 10 | cin>>t; 11 | while(t--) 12 | { 13 | int flag = 0; 14 | cin>>n; 15 | ll a[100001]; 16 | for(int i=0; i>a[i]; 18 | } 19 | sort(a,a+n); 20 | 21 | for(int i=n-1; i>=0; i--){ 22 | if(a[i] <= i+1){ 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,i; 6 | cin>>n; 7 | int a[n+1]; 8 | for(i=1; i<=n; i++) 9 | { 10 | cin>>m; 11 | a[m]=i; 12 | } 13 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int t,a,b; 9 | cin>>t; 10 | while(t--){ 11 | cin>>a>>b; 12 | if(a > b){ 13 | swap(a,b); 14 | } 15 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int t,n,a[100]; 9 | cin>>t; 10 | while(t--) 11 | { 12 | cin>>n; 13 | for(int i=0; i>a[i]; 15 | } 16 | sort(a,a+n); 17 | vectorv; 18 | int dif = 0; 19 | for(int i=1; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n,x,a; 12 | cin>>t; 13 | while(t--) 14 | { 15 | int even = 0,odd = 0; 16 | cin>>n>>x; 17 | for(int i=0; i>a; 19 | if(a % 2 == 1)odd++; 20 | else even++; 21 | } 22 | int m = min(even,x-1); 23 | int d = x - m; 24 | 25 | if(d % 2 == 0){ 26 | d++; 27 | } 28 | if(odd >= d && d <= x)cout<<"Yes\n"; 29 | else cout<<"No\n"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /1365 C. Rotation Matching.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n; 12 | cin>>n; 13 | ll a[n+5],b[n+5],index[n+5]; 14 | for(ll i=0; i>a[i]; 16 | index[a[i]] = i; 17 | } 18 | mapmp; 19 | for(ll i=0; i>b[i]; 21 | mp[(i-index[b[i]]+n)%n]++; 22 | } 23 | ll Max = 0; 24 | map:: iterator itr; 25 | for(itr=mp.begin(); itr!=mp.end(); itr++){ 26 | Max = max(Max,itr->second); 27 | } 28 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | ll a,b; 12 | cin>>t; 13 | while(t--) 14 | { 15 | cin>>a>>b; 16 | if(a > b){ 17 | swap(a,b); 18 | } 19 | if(a*2 <= b){ 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | string s,t; 15 | cin>>s; 16 | int len = s.length(); 17 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t,n; 11 | cin>>t; 12 | while(t--){ 13 | cin>>n; 14 | if(n % 4 == 0){ 15 | cout<<"YES\n"; 16 | } 17 | else{ 18 | cout<<"NO\n"; 19 | } 20 | } 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /1370 A. Maximum GCD.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | ll n; 12 | cin>>t; 13 | while(t--) 14 | { 15 | cin>>n; 16 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | cin>>t; 13 | while(t--){ 14 | int ans = 0; 15 | cin>>n; 16 | ans = n/2; 17 | if(n % 2 == 1)ans++; 18 | 19 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll n,r; 13 | cin>>t; 14 | while(t--){ 15 | ll ans = 0,m = 0; 16 | cin>>n>>r; 17 | if(n > r){ 18 | m = min(n,r); 19 | ans = m*(m+1)/2; 20 | } 21 | else{ 22 | m = min(n,r); 23 | m--; 24 | ans = m*(m+1)/2; 25 | ans++; 26 | } 27 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | ll a,b,c,f,s; 12 | cin>>t; 13 | while(t--){ 14 | f = -1,s = -1; 15 | cin>>a>>b>>c; 16 | 17 | if(a < c){ 18 | f = 1; 19 | } 20 | if(a*b > c){ 21 | s = b; 22 | } 23 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | int one = 0, zero = 0; 14 | string s; 15 | cin>>s; 16 | int n = s.length(); 17 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll t; 12 | ll x,y,n; 13 | cin>>t; 14 | while(t--){ 15 | cin>>x>>y>>n; 16 | ll ans = 0; 17 | ans = n - n % x + y; 18 | if(ans <= n){ 19 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | ll a[100]; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n; 16 | for(int i=0; i>a[i]; 18 | if(i%2 == 0){ 19 | a[i] = abs(a[i]); 20 | } 21 | else{ 22 | a[i] = abs(a[i]) * -1; 23 | } 24 | } 25 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | 9 | ll a[300001]; 10 | int main() 11 | { 12 | fastread(); 13 | ll t,n; 14 | cin>>t; 15 | while(t--){ 16 | cin>>n; 17 | 18 | for(ll i=0; i>a[i]; 20 | } 21 | if(a[0] < a[n-1]){ 22 | cout<<"YES\n"; 23 | } 24 | else{ 25 | cout<<"NO\n"; 26 | } 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1385 A. Three Pairwise Maximums.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll t,x,y,z; 12 | cin>>t; 13 | while(t--){ 14 | cin>>x>>y>>z; 15 | if(x > y)swap(x,y); 16 | if(x > z)swap(x,z); 17 | if(y > z)swap(y,z); 18 | if(y == z){ 19 | cout<<"YES\n"; 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll t; 12 | ll l,r; 13 | cin>>t; 14 | while(t--){ 15 | ll x = 0,y = 0; 16 | cin>>l>>r; 17 | if(l*2 <= r){ 18 | x = l; 19 | y = l * 2; 20 | } 21 | else{ 22 | x = -1; 23 | y = -1; 24 | } 25 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | cin>>t; 13 | while(t--){ 14 | int a[101]; 15 | cin>>n; 16 | int j = n; 17 | for(int i=1; i<=n; i++){ 18 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll n,a; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n; 16 | sets; 17 | for(ll i=0; i>a; 19 | s.insert(a); 20 | } 21 | if(s.size() == 1){ 22 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll n; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n; 16 | cout<<(n/2)+1< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | cin>>t; 13 | while(t--){ 14 | string s; 15 | cin>>n>>s; 16 | for(int i=0; i<2*n-1; i+=2){ 17 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t; 12 | ll n,k; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n>>k; 16 | if(n < k){ 17 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | int a[101]; 16 | for(int i=0; i>a[i]; 18 | } 19 | for(int i=n-1; i>=0; i--){ 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll t; 12 | ll a,b; 13 | cin>>t; 14 | while(t--){ 15 | cin>>a>>b; 16 | if(b < a){ 17 | swap(a,b); 18 | } 19 | ll sub = 0,sum = 0,div = 0,mod = 0; 20 | sub = b - a; 21 | div = sub / 10; 22 | mod = sub % 10; 23 | sum = div; 24 | if(mod > 0){ 25 | sum++; 26 | } 27 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n,k; 12 | ll a[1001]; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n>>k; 16 | for(int i=0; i>a[i]; 18 | } 19 | sort(a,a+n); 20 | ll s = a[0]; 21 | ll rest = 0,ans = 0; 22 | for(int i=1; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll t; 12 | ll x,y,k; 13 | cin>>t; 14 | while(t--){ 15 | cin>>x>>y>>k; 16 | long double coal,sticks,div,need; 17 | ll ans = 0; 18 | coal = sticks = div = 0; 19 | coal = y * k; 20 | sticks = coal + (k-1); 21 | div = ceil(sticks/(x-1)); 22 | ans = div + k; 23 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,a,b; 11 | cin>>t; 12 | while(t--){ 13 | ll d = 0; 14 | cin>>a>>b; 15 | d = a ^ b; 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n; 11 | cin>>t; 12 | while(t--){ 13 | ll a,b,c; 14 | cin>>a>>b>>c; 15 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int t,n,x; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n>>x; 15 | int c = 2,ans = 1; 16 | while(c < n){ 17 | c += x; 18 | ans++; 19 | } 20 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t; 11 | cin>>t; 12 | ll x1,y1,x2,y2; 13 | while(t--){ 14 | ll ans = 0; 15 | cin>>x1>>y1>>x2>>y2; 16 | if(x1 == x2 || y1 == y2){ 17 | ans = abs(x1 - x2) + abs(y1 - y2); 18 | } 19 | else{ 20 | ans = abs(x1 - x2) + abs(y1 - y2) + 2; 21 | } 22 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n,k; 11 | ll a[200005]; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n>>k; 15 | for(ll i=0; i>a[i]; 17 | 18 | } 19 | sort(a,a+n,greater()); 20 | ll m = a[0]; 21 | ll i = 1; 22 | while(k--){ 23 | m += a[i]; 24 | a[i] = 0; 25 | i++; 26 | } 27 | sort(a,a+n); 28 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n,a[101]; 11 | cin>>t; 12 | while(t--){ 13 | cin>>n; 14 | for(int i=0; i>a[i]; 16 | } 17 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n,m,a; 11 | cin>>t; 12 | while(t--){ 13 | cin>>n>>m; 14 | ll sum = 0; 15 | for(int i=0; i>a; 17 | sum += a; 18 | } 19 | 20 | if(sum == m){ 21 | cout<<"YES"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll t,n; 11 | cin>>t; 12 | while(t--){ 13 | cin>>n; 14 | int x = 0,y = 1; 15 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll t,n; 14 | cin>>t; 15 | while(t--){ 16 | cin>>n; 17 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll t,n; 14 | cin>>t; 15 | while(t--){ 16 | ll range = 0; 17 | cin>>n; 18 | range = 4 * n; 19 | range -= 2; 20 | while(n--){ 21 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll t; 14 | ll a,b,c,d; 15 | cin>>t; 16 | while(t--){ 17 | cin>>a>>b>>c>>d; 18 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll t,n; 14 | cin>>t; 15 | while(t--){ 16 | cin>>n; 17 | if(n == 2){ 18 | cout<<1< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | string s; 15 | cin>>n>>s; 16 | sort(s.begin(),s.end()); 17 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | if(n <= 3){ 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,x,y; 12 | cin>>t; 13 | while(t--){ 14 | ll sum = 0, sub = 0,m = 10001; 15 | cin>>x>>y; 16 | if(x == y){ 17 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | vectorv; 16 | for(int i=n; i>0; i--){ 17 | v.pb(i); 18 | } 19 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t; 12 | cin>>t; 13 | while(t--){ 14 | string s; 15 | cin>>s; 16 | 17 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | ll k=1,cur = 0; 15 | cin>>n; 16 | while(cur < n){ 17 | cur += k; 18 | k++; 19 | } 20 | 21 | if(cur == n+1){ 22 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n,m,r,c; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n>>m>>r>>c; 15 | ll dis = 0; 16 | dis = max(dis,(r-1) + (c-1)); 17 | dis = max(dis,((n-r) + (c-1))); 18 | dis = max(dis,((r-1) + (m-c))); 19 | dis = max(dis,(n-r) + (m-c)); 20 | 21 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n,k; 12 | cin>>t; 13 | while(t--){ 14 | string s[] = {"a","b","c"}; 15 | string a; 16 | cin>>n>>k; 17 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | ll k = 9; 15 | cin>>n; 16 | for(ll i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | ll mod = n % 2020; 16 | ll div = n / 2020; 17 | 18 | if( mod <= div){ 19 | cout<<"YES"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n,a[105]; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n; 15 | mapmp; 16 | for(ll i=0; i>a[i]; 18 | mp[a[i]]++; 19 | } 20 | ll ans = 0; 21 | map::iterator itr; 22 | for(itr=mp.begin(); itr!=mp.end(); itr++){ 23 | ans = max(ans,itr->second); 24 | } 25 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll t,n,m,x; 12 | cin>>t; 13 | while(t--){ 14 | cin>>n>>m>>x; 15 | 16 | ll col = (x/n); 17 | if(x%n != 0)col++; 18 | ll row = x % n; 19 | if(row == 0)row = n; 20 | 21 | ll ans = ((row - 1) * m) + col; 22 | 23 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,k,a[100],d = 0; 12 | cin>>n>>k; 13 | for(int i=1; i<=n; i++){ 14 | cin>>a[i]; 15 | if(k == i){ 16 | d = a[i]; 17 | } 18 | } 19 | int ans = 0; 20 | for(int i=1; i<=n; i++){ 21 | if(a[i] >= d && a[i] > 0){ 22 | ans++; 23 | } 24 | } 25 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n,a; 11 | int mp[5]; 12 | memset(mp,0,sizeof(mp)); 13 | cin>>n; 14 | for(int i=0; i>a; 16 | mp[a]++; 17 | } 18 | int ans = 0; 19 | ans += mp[4] + mp[3] + (mp[2] / 2); 20 | mp[1] -= min(mp[3],mp[1]); 21 | if (mp[2] & 1) 22 | { 23 | mp[1] -= min(2, mp[1]); 24 | ans ++; 25 | } 26 | ans += (mp[1] + 3) / 4; 27 | 28 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll d,n,a,ans = 0; 14 | cin>>d>>n; 15 | for(ll i=0; i>a; 17 | if(i+1 == n)continue; 18 | else 19 | ans += (abs(d - a)); 20 | } 21 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll a,b,c; 14 | cin>>a>>b>>c; 15 | 16 | ll total = 0,will = 0,need = 0,ans = 0; 17 | total = a * c; 18 | will = b * c; 19 | need = total - will; 20 | ans = (need / b); 21 | if(need % b != 0){ 22 | ans++; 23 | } 24 | 25 | cout< 2 | using namespace std; 3 | typedef long long ll; 4 | int n,m,i,j,a,b,w,k,z; 5 | ll d[100005],p[100005]; 6 | map ,ll> mp; 7 | priority_queue q; 8 | vectorv[100005]; 9 | void f (ll i) 10 | { 11 | if (i!=1) f(p[i]); 12 | cout<>n>>m; 17 | while (m--) 18 | { 19 | cin>>a>>b>>w; 20 | v[a].push_back(b); 21 | v[b].push_back(a); 22 | mp[{a,b}]=w; 23 | mp[{b,a}]=w; 24 | } 25 | 26 | for (i=2; i<=n; i++) 27 | d[i]=1e18; 28 | q.push(1); 29 | 30 | while (q.size()) 31 | { 32 | k=q.top(); 33 | q.pop(); 34 | for (i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a[110]; 6 | cin>>n; 7 | double ans=0.0,sum=0.0; 8 | for(int i=0; i>a[i]; 11 | sum+=a[i]; 12 | } 13 | ans=sum/n; 14 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n=4,c=0,dif=0; 6 | long long int a[15]; 7 | for(int i=0; i>a[i]; 9 | sort(a,a+n); 10 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a[5],solved=0; 6 | cin>>n; 7 | while(n--) 8 | { 9 | int a,b,c; 10 | cin>>a>>b>>c; 11 | //cin>>a[0]>>a[1]>>a[2]; 12 | //if(((a[0]==1) && (a[1]==1)) || ((a[1]==1) && (a[2]==1)) || ((a[2]==1) && (a[0]==1)) ) 13 | if(a+b+c>=2) 14 | solved++; 15 | } 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | freopen("input.txt","r", stdin); 11 | freopen("output.txt", "w", stdout); 12 | int n,k,a; 13 | 14 | cin>>n>>k; 15 | vector< pair > v; 16 | for(int i=1; i<=n; i++){ 17 | cin>>a; 18 | v.pb(make_pair(a,i)); 19 | } 20 | sort(v.begin(),v.end()); 21 | reverse(v.begin(),v.end()); 22 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | sort(s.begin(),s.end()); 8 | int l=s.length(); 9 | int ans=0; 10 | for(int i=1; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll n,c = 0,ans = 1; 12 | string h,m,s; 13 | mapmp; 14 | map::iterator itr; 15 | cin>>n; 16 | for(ll i=0; i>h>>m; 18 | s = h + '_' + m; 19 | mp[s]++; 20 | } 21 | for(itr=mp.begin(); itr!=mp.end(); itr++){ 22 | c = itr->second; 23 | ans = max(ans,c); 24 | } 25 | cout< 2 | using namespace std; 3 | int loss[3] , live[3]; 4 | int n , x , a , b; 5 | int main() 6 | { 7 | cin>>n; 8 | while(n--) 9 | { 10 | cin>>x>>a>>b; 11 | live[x]+=a; 12 | loss[x]+=b; 13 | } 14 | for(int j=1;j<=2;j++) 15 | if(live[j] < loss[j]) 16 | cout<<"DEAD"< 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j,ans=0,n; 6 | for(i=1; i<=5; i++) 7 | for(j=1; j<=5; j++) 8 | { 9 | cin>>n; 10 | if(n==1) 11 | ans=abs(i-3)+abs(j-3); 12 | } 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,c=0; 6 | string s; 7 | cin>>n>>s; 8 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | putchar(toupper(s[0])); 8 | for(int i=1; i 3 | using namespace std; 4 | int main() 5 | { 6 | int n; 7 | cin>>n; 8 | int c=0; 9 | while(n--) 10 | { 11 | string s; 12 | cin>>s; 13 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,k,div = 0,ans = 0; 12 | cin>>n>>k; 13 | 14 | div = (n + 1) / 2; 15 | if(k <= div){ 16 | ans = (k * 2) - 1; 17 | } 18 | else{ 19 | ans = (k - div) * 2; 20 | } 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,d,c=0,i,j; 6 | cin>>n>>d; 7 | int a[n+5]; 8 | for(i=0; i>a[i]; 10 | sort(a,a+n); 11 | for(i=0; id)break; 16 | c++; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j; 6 | string s; 7 | cin>>s; 8 | int len=s.length(); 9 | int a[len+5]; 10 | for(i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,a[101],b[101]; 12 | cin>>n; 13 | for(int i=0; i>a[i]; 15 | } 16 | int m = 1001, d = 0; 17 | d = abs(a[0] - a[n-1]); 18 | m = min(m,d); 19 | int idx1 = 1,idx2 = n; 20 | for(int i=0; i d){ 23 | m = d; 24 | idx1 = i+1; 25 | idx2 = i+2; 26 | } 27 | } 28 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,m,a; 12 | cin>>n>>m; 13 | vectorv; 14 | for(int i=0; i>a; 16 | if(a < 0){ 17 | v.push_back(a); 18 | } 19 | } 20 | sort(v.begin(),v.end()); 21 | n = v.size(); 22 | if(n > m){ 23 | swap(n,m); 24 | } 25 | int sum = 0; 26 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i,c=0; 6 | cin>>n; 7 | int a[100000]; 8 | i=0; 9 | for(i=0; i>a[i]; 11 | 12 | for(i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll a,b; 11 | ll div = 0,temp = 0; 12 | cin>>a>>b; 13 | ll ans = a; 14 | while(a >= b){ 15 | if(a % b == 0){ 16 | a /= b; 17 | ans += a; 18 | } 19 | else{ 20 | temp = a; 21 | a /= b; 22 | ans += a; 23 | a += temp % b; 24 | 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int i,n,a,b,sum=0; 6 | cin>>n; 7 | int p[n]; 8 | for(i=0; i>p[i]; 10 | cin>>a>>b; 11 | a--; 12 | b--; 13 | for(i=a; i 2 | using namespace std; 3 | int main() 4 | { 5 | int w; 6 | cin>>w; 7 | if(w%2==0 && w>2) 8 | cout<<"YES"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | string s; 13 | mapmp; 14 | cin>>n; 15 | while(n--){ 16 | cin>>s; 17 | if(mp.count(s) == 0){ 18 | cout<<"OK"< 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j,len,len2,tag=0; 6 | string x,y; 7 | cin>>x>>y; 8 | len=x.length(); 9 | len2=y.length(); 10 | for(i=0, j=len2-1; i=0; i++, j--) 11 | //for(j=len2-1; j>=0; j--) 12 | { 13 | if(x[i]==y[j]) 14 | tag=1; 15 | else 16 | { 17 | tag=0; 18 | break; 19 | } 20 | } 21 | if(tag==1) 22 | cout<<"YES"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | int n; 14 | cin>>n; 15 | mapmp; 16 | string s; 17 | for(int i=0; i>s; 19 | mp[s]++; 20 | } 21 | int c = 0,d = 0; 22 | string t; 23 | map:: iterator itr; 24 | for(itr = mp.begin(); itr!=mp.end(); itr++){ 25 | c = itr->second; 26 | if(c > d){ 27 | d = c; 28 | t = itr->first; 29 | } 30 | } 31 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n; 11 | string a,b,c; 12 | cin>>n; 13 | 14 | sets; 15 | while(n--){ 16 | cin>>a>>b; 17 | c = b+a; 18 | s.insert(c); 19 | } 20 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | set a; 7 | getline(cin,s); 8 | for(int i=0; i='a' && s[i]<='z') 11 | a.insert(s[i]); 12 | } 13 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | cin>>n; 13 | int N = n; 14 | n -= 1; 15 | int go = 1,i = 1; 16 | while(n--){ 17 | go += i; 18 | if(go % N == 0){ 19 | go = go; 20 | } 21 | else{ 22 | go %= N; 23 | } 24 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,people,capacity,c=0; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>people>>capacity; 10 | if(capacity-people>=2) 11 | c++; 12 | } 13 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,p,a; 12 | sets; 13 | cin>>n; 14 | cin>>p; 15 | for(int i=0; i>a; 17 | s.insert(a); 18 | } 19 | cin>>p; 20 | for(int i=0; i>a; 22 | s.insert(a); 23 | } 24 | if(n == s.size()){ 25 | cout<<"I become the guy.\n"; 26 | } 27 | else{ 28 | cout<<"Oh, my keyboard!\n"; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /47 A. Triangular numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isTriangular(int num) 4 | { 5 | if (num < 0) 6 | return false; 7 | 8 | int sum = 0; 9 | for (int n=1; sum<=num; n++) 10 | { 11 | sum = sum + n; 12 | if (sum==num) 13 | return true; 14 | } 15 | 16 | return false; 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | cin>>n; 23 | if(isTriangular(n)) 24 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,m,pairs(0); 7 | cin>>n; 8 | int a[n]; 9 | for(int i=0; i>a[i]; 11 | 12 | cin>>m; 13 | int b[m]; 14 | for(int i=0; i>b[i]; 16 | 17 | sort(a,a+n); 18 | sort(b,b+m); 19 | for(int i=0; i 2 | using namespace std; 3 | int main(){ 4 | string s; 5 | getline(cin, s); 6 | for (int i = s.size() - 1; i >= 0; i--) 7 | if(('A' <= s[i] && s[i] <= 'Z') || ('a' <= s[i] && s[i] <= 'z')){ 8 | if(s[i] == 'a' || s[i] == 'A' || s[i] == 'E' || s[i] == 'e' || s[i] == 'I' || s[i] == 'i' || s[i] == 'O' || s[i] == 'o' || s[i] == 'U' || s[i] == 'u' || s[i] == 'Y' || s[i] == 'y') 9 | cout << "YES" << endl; 10 | else 11 | cout << "NO" << endl; 12 | return 0; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /50 A. Domino piling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int a,b,sum; 5 | int main() 6 | { 7 | cin>>a>>b; 8 | sum=(a*b)/2; 9 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | int a[15][15]; 8 | for(int i=1; i<=1; i++) 9 | { 10 | for(int j=1; j<=n; j++) 11 | a[i][j]=1; 12 | } 13 | for(int i=2; i<=n; i++) 14 | { 15 | a[i][1]=1; 16 | for(int j=2; j<=n; j++) 17 | { 18 | a[i][j]=a[i-1][j]+a[i][j-1]; 19 | } 20 | } 21 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n,a; 11 | cin>>n; 12 | int one = 0,two = 0,three = 0; 13 | for(int i=0; i>a; 15 | if(a == 1)one++; 16 | else if(a == 2)two++; 17 | else three++; 18 | } 19 | 20 | int m = 0, ans = 0; 21 | m = max(one,max(two,three)); 22 | ans = (one + two + three); 23 | ans = abs(m - ans); 24 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int len; 6 | cin>>len; 7 | string s; 8 | setS; 9 | cin>>s; 10 | 11 | for(int i=0; i= 'A' && s[i] <= 'Z') s[i] += 'a' - 'A'; 14 | S.insert(s[i]); 15 | } 16 | if(S.size()==26) 17 | cout<<"YES"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n; 11 | ll a[100001]; 12 | cin>>n; 13 | for(int i=0; i>a[i]; 15 | } 16 | sort(a,a+n); 17 | ll sum = 0; 18 | int c = 0; 19 | for(int i=0; i 2 | int main() 3 | { 4 | int i; 5 | long long int k,n,w,ans=0; 6 | scanf("%lld%lld%lld",&k,&n,&w); 7 | for(i=0; i<=w; i++) 8 | { 9 | ans+=i*k; 10 | } 11 | ans-=n; 12 | if(ans<0) 13 | { 14 | ans=0; 15 | } 16 | printf("%lld\n",ans); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /550 A. Two Substrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | char s[100005],*t; 6 | cin>>s; 7 | if((t=strstr(s,"AB")) && (strstr(t+2,"BA"))) 8 | { 9 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | string s,target; 6 | cin>>s; 7 | 8 | target = "hello"; 9 | int n = s.length(); 10 | 11 | int k = 0; 12 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i,b; 6 | cin>>n; 7 | b=n; 8 | for(i=n; i>=1; i--) 9 | { 10 | if(b%i==0) 11 | { 12 | b=i; 13 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | ll a[100001]; 13 | cin>>n; 14 | for(int i=0; i>a[i]; 16 | } 17 | ll ans = 0,c = 1; 18 | for(int i=1; i= a[i-1]){ 20 | c++; 21 | } 22 | else{ 23 | ans = max(ans,c); 24 | c = 1; 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b; 6 | int c=0,d=0; 7 | cin>>a>>b; 8 | if(a==b) 9 | cout<1 && b>0) 15 | { 16 | a--; 17 | b--; 18 | c++; 19 | } 20 | if(a>1) 21 | d=a/2; 22 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int lenX,i,upcase=0,lowcase=0; 6 | int findA=0,finda=0; 7 | string x; 8 | cin>>x; 9 | lenX=x.length(); 10 | for(i=0; i='a' && x[i]<='z') 13 | lowcase++; 14 | else 15 | upcase++; 16 | } 17 | findA=lenX-lowcase; 18 | finda=lenX-upcase; 19 | if((findA==finda) || (finda >=findA)) 20 | transform(x.begin(), x.end(), x.begin(), :: tolower); 21 | else 22 | transform(x.begin(), x.end(), x.begin(), :: toupper); 23 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll d1,d2,d3; 11 | cin>>d1>>d2>>d3; 12 | 13 | ll len_1 = 0, len_2 = 0,len_3 = 0,len_4 = 0; 14 | len_1 = (d1 * 2) + (d2 * 2); 15 | len_2 = d1 + d2 + d3; 16 | len_3 = (d1 * 2) + (d3 * 2); 17 | len_4 = (d2 * 2) + (d3 * 2); 18 | 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a[101]; 6 | long long int m,sum=0; 7 | cin>>n>>m; 8 | for(int i=0; i>a[i]; 10 | } 11 | sort(a,a+n,greater()); 12 | 13 | int c=0; 14 | for(int i=0; i=m){ 18 | break; 19 | } 20 | } 21 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | string a,b,c; 12 | cin>>a>>b; 13 | int n = a.length(); 14 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,ans=0; 6 | int a[]={5,4,3,2,1}; 7 | cin>>n; 8 | for(int i=0; i<5; i++) 9 | { 10 | ans+=n/a[i]; 11 | n=n%a[i]; 12 | } 13 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n,temp = 0,i = 1; 11 | cin>>n; 12 | n--; 13 | while(1){ 14 | n -= i; 15 | i++; 16 | if(n < 0){ 17 | break; 18 | } 19 | else{ 20 | temp = n; 21 | } 22 | } 23 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int h,m,a; 11 | char c; 12 | int hr,mi; 13 | cin>>h>>c>>m>>a; 14 | mi = m + a; 15 | hr = mi / 60; 16 | mi %= 60; 17 | hr = (h + hr) % 24; 18 | 19 | if(hr < 10 && mi < 10){ 20 | cout<<0<= 10 && mi < 10){ 23 | cout<= 10){ 26 | cout<<0< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | ll a[1001]; 13 | cin>>n; 14 | for(int i=0; i>a[i]; 16 | } 17 | sort(a,a+n); 18 | vectorv; 19 | int N = n/2; 20 | if(n%2 == 1){ 21 | N = (n/2) +1; 22 | } 23 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll n,c; 14 | string s; 15 | setSET; 16 | 17 | cin>>n>>s; 18 | 19 | for(ll i=0; i 26){ 25 | cout<<-1< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,h,ans=0; 6 | cin>>n>>h; 7 | int a[n+10]; 8 | for(int i=0; i>a[i]; 11 | if(a[i]>h) 12 | ans+=2; 13 | else 14 | ans+=1; 15 | } 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | int a=0,b=0,c=0,x,y,z; 7 | cin>>t; 8 | for(int i=0; i>x>>y>>z; 11 | a+=x; 12 | b+=y; 13 | c+=z; 14 | 15 | } 16 | if(a==0 && b==0 && c==0) 17 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | int m,c; 8 | int winM=0,winC=0,draw=0; 9 | for(int i=0; i>m>>c; 12 | 13 | if(m>c) 14 | winM++; 15 | else if(mwinC) 23 | cout<<"Mishka"; 24 | else 25 | cout<<"Chris"; 26 | 27 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | if(n==1) 8 | cout<<"I hate it"; 9 | else if(n>1) 10 | cout<<"I hate that"; 11 | for(int i=2; i1) 21 | cout<<" I love it"; 22 | else if(n>1) 23 | cout<<" I hate it"; 24 | cout< 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,i,l; 8 | char s[100]; 9 | scanf("%d",&n); 10 | for(i=0; i10) 15 | { 16 | printf("%c",s[0]); 17 | printf("%d",l-2); 18 | printf("%c\n",s[l-1]); 19 | } 20 | else 21 | printf("%s\n",s); 22 | } 23 | return 0; 24 | } 25 | /* 26 | SIMPLE INPUT 27 | 4 28 | word 29 | localization 30 | internationalization 31 | pneumonoultramicroscopicsilicovolcanoconiosis 32 | */ 33 | -------------------------------------------------------------------------------- /716 A. Crazy Computer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,t,i,LastTime,Words,a; 6 | Words=LastTime=0; 7 | cin>>n>>t; 8 | 9 | for(i=0; i>a; 12 | if(a-LastTime>t) 13 | Words=0; 14 | Words++; 15 | LastTime=a; 16 | } 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,wonAnton=0,wonDanik=0; 6 | string s; 7 | cin>>n; 8 | cin>>s; 9 | for(int i=0; iwonDanik) 19 | cout<<"Anton"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int a,b,c,sum = 0; 12 | cin>>a>>b>>c; 13 | int flag = 0; 14 | while(flag != 1){ 15 | if(a*2 <= b && ((a*2)*2) <= c){ 16 | sum = a + a*2 + (a*2)*2; 17 | flag = 1; 18 | } 19 | else{ 20 | a--; 21 | } 22 | } 23 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,div = 0; 12 | cin>>n; 13 | if(n % 2 == 1){ 14 | div = (n/2); 15 | cout< 2 | using namespace std; 3 | int removezeros(int num) 4 | { 5 | int retrn=0; 6 | int ten=1; 7 | while(num) 8 | { 9 | int mod=num%10; 10 | num/=10; 11 | if(mod) 12 | { 13 | retrn+=mod*ten; 14 | ten*=10; 15 | } 16 | } 17 | return retrn; 18 | } 19 | int main() 20 | { 21 | long long int a,b,c,i; 22 | cin>>a>>b; 23 | c=a+b; 24 | a=removezeros(a); 25 | b=removezeros(b); 26 | c=removezeros(c); 27 | if(a+b==c) 28 | cout<<"YES"< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,k; 12 | cin>>n>>k; 13 | int time = 240,need = 0,ans = 0; 14 | time -= k; 15 | for(int i=1; i<=n; i++){ 16 | need += i * 5; 17 | if(need <= time){ 18 | ans++; 19 | } 20 | else{ 21 | break; 22 | } 23 | } 24 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,ans=0; 6 | cin>>n; 7 | long long int a[105]; 8 | for(int i=0; i>a[i]; 10 | sort(a,a+n); 11 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll n, m, un = 0,c = 0; 12 | string a,b; 13 | cin>>a>>b; 14 | n = a.length(), m = b.length(); 15 | if(a == b){ 16 | cout<<-1< 3 | using namespace std; 4 | int main() 5 | { 6 | string f,l; 7 | int n; 8 | cin>>f>>l; 9 | cin>>n; 10 | cout<>next>>later; 14 | if(f==next){ 15 | f=later; 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,x; 6 | cin>>n>>x; 7 | n%=6; 8 | int a[4]; 9 | a[0]=0,a[1]=1,a[2]=2; 10 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int t,ans=0; 6 | cin>>t; 7 | 8 | char s0[]="Tetrahedron"; 9 | char s1[]="Cube"; 10 | char s2[]="Octahedron"; 11 | char s3[]="Dodecahedron"; 12 | char s4[]="Icosahedron"; 13 | 14 | while(t--) 15 | { 16 | char m[15]=""; 17 | cin>>m; 18 | if(0==strcmp(m,s0)) 19 | ans+=4; 20 | if(0==strcmp(m,s1)) 21 | ans+=6; 22 | if(0==strcmp(m,s2)) 23 | ans+=8; 24 | if(0==strcmp(m,s3)) 25 | ans+=12; 26 | if(0==strcmp(m,s4)) 27 | ans+=20; 28 | } 29 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,c=0; 6 | cin>>a>>b; 7 | if(a>b) 8 | c=0; 9 | else 10 | while(a<=b) 11 | { 12 | a=a*3; 13 | b=b*2; 14 | c++; 15 | } 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int i,j,c=0; 8 | string x; 9 | cin>>x; 10 | int len=x.length(); 11 | 12 | for(i=0, j=len-1; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | 12 | ll l,r; 13 | cin>>l>>r; 14 | 15 | if(l == r){ 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | 12 | ll n,j = 0; 13 | cin>>n; 14 | string s[] = {"b","b","a","a"}; 15 | 16 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,ans = 0; 12 | cin>>n; 13 | ll a = 1; 14 | while(a <= n) { 15 | a *= 10; 16 | } 17 | a /= 10; 18 | ll b = a; 19 | while(b <= n) { 20 | b += a; 21 | } 22 | ans = b - n; 23 | 24 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,a,need = 0; 12 | double sum = 0.0,k; 13 | 14 | cin>>n>>k; 15 | for(int i=0; i>a; 17 | sum+=a; 18 | } 19 | double div = 0.0,range = 0.0; 20 | div = sum / n; 21 | range = k - 0.5; 22 | while(div < range){ 23 | need++; 24 | sum += k; 25 | n++; 26 | div = sum/n; 27 | } 28 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | int main() 7 | { 8 | int c,vo,v1,a,l; 9 | cin>>c>>vo>>v1>>a>>l; 10 | 11 | int cnt=1,read=0,have=0; 12 | 13 | have = read = vo; 14 | while(have < c) 15 | { 16 | read = min(v1,read + a); 17 | have += read - l; 18 | cnt++; 19 | } 20 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll a,b; 11 | cin>>a>>b; 12 | ll A = 1, B = 1; 13 | for(ll i=2; i<=min(a,b); i++){ 14 | A *= i; 15 | } 16 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n,a; 11 | cin>>n; 12 | ll odd = 0,even = 0; 13 | for(ll i=0; i>a; 15 | if(a & 1){ 16 | odd++; 17 | } 18 | else{ 19 | even++; 20 | } 21 | } 22 | if(odd > 0){ 23 | cout<<"First"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll k,n,c = 0; 14 | string s; 15 | setSET; 16 | cin>>s>>k; 17 | 18 | n = s.length(); 19 | for(ll i=0; i= k){ 25 | cout<<0<= k){ 28 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt", "r", stdin); 11 | int n,one = 0,mx = 0; 12 | string s[1001]; 13 | cin>>n; 14 | for(int i=0; i>s[i]; 16 | } 17 | for(int i=0; i<7; i++){ 18 | for(int j=0; j 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,a,b; 12 | cin>>n; 13 | if(n == 3){ 14 | cout<<1<<" "<<2< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | string s[110]; 7 | cin>>n; 8 | for(int i=0; i>s[i]; 12 | for(int j=0; j 2 | using namespace std; 3 | //we have to find if we flew more times from San to Francisco 4 | int main() 5 | { 6 | int n,StoF=0,FtoS=0; 7 | string s; 8 | cin>>n; 9 | cin>>s; 10 | for(int i=0; iFtoS) 18 | cout<<"YES"< 3 | using namespace std; 4 | int main() 5 | { 6 | long long int a[86500],c=0,i,n; 7 | int t,day=86400; 8 | 9 | cin>>n>>t; 10 | 11 | for(i=0; i>a[i]; 13 | } 14 | 15 | for(i=0; i0 ) ){ 17 | c++; 18 | t-=( day - a[i] ); 19 | } 20 | else if( ( a[i] < day && a[i] > 0 ) && ( t > 0 ) ){ 21 | t-=( day - a[i]); 22 | c++; 23 | } 24 | else if( ( a[i] >= day ) && ( t > 0 ) ){ 25 | c++; 26 | } 27 | } 28 | 29 | cout< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | int n, zeros = 0; 12 | string s; 13 | bool ok = false; 14 | cin>>s; 15 | n = s.length(); 16 | for(int i=0; i= 6){ 25 | cout<<"yes\n"; 26 | } 27 | else{ 28 | cout<<"no\n"; 29 | } 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /897 A. Scarborough Fair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,l,r; 6 | string s,c1,c2; 7 | cin>>n>>m; 8 | cin>>s; 9 | while(m--) 10 | { 11 | cin>>l>>r>>c1>>c2; 12 | for(int i=l-1; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n; 12 | cin>>n; 13 | ll mod = n % 10; 14 | if(mod <= 5){ 15 | n -= mod; 16 | } 17 | else{ 18 | n += (10 - mod); 19 | } 20 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | ll n,a; 12 | mapmp; 13 | cin>>n; 14 | for(int i=0; i>a; 16 | mp[a]++; 17 | } 18 | ll ans = 0,temp; 19 | map:: iterator itr; 20 | for(itr = mp.begin(); itr != mp.end(); itr++){ 21 | temp = itr->second; 22 | ans = max(ans,temp); 23 | } 24 | cout< 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,m; 12 | cin>>n>>m; 13 | ll prod = pow(2,n); 14 | ll mod = m % prod; 15 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | long long int ans=-1000005,n,a,i,j; 7 | cin>>n; 8 | for(i=0; i>a; 10 | if(a < 0){ 11 | ans = max(ans,a); 12 | } 13 | else{ 14 | int tag=0; 15 | for(j=0; j*j <= a; j++)if(j*j == a)tag=1; 16 | if(tag == 0)ans = max(ans,a); 17 | } 18 | } 19 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n,k; 7 | cin>>n>>k; 8 | int a[n+5]; 9 | int ans=0; 10 | for(int i=0; i>a[i]; 12 | sort(a,a+n); 13 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,m; 12 | cin>>n>>m; 13 | string name,ip; 14 | mapmp; 15 | for(int i=0; i>name>>ip; 17 | ip += ';'; 18 | mp[ip] = name; 19 | } 20 | 21 | for(int i=0; i>name>>ip; 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,c=0; 6 | cin>>n; 7 | for(int i=1; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll n,a[5001]; 14 | cin>>n; 15 | 16 | for(int i=1; i<=n; i++){ 17 | cin>>a[i]; 18 | } 19 | int flag = 0; 20 | for(int i = 1; i<=n; i++){ 21 | if(a[a[a[i]]] == i){ 22 | flag = 1; 23 | break; 24 | } 25 | } 26 | if(flag == 1){ 27 | cout<<"YES"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | 11 | //freopen("input.txt","r", stdin); 12 | 13 | ll n,k,a[100001]; 14 | cin>>n>>k; 15 | for(ll i=0; i>a[i]; 17 | } 18 | ll ans = 0,type = 0,mod = 0; 19 | vector< pair >v; 20 | for(ll i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | if(n%2==0) 8 | cout<<"Mahmoud"< 3 | using namespace std; 4 | int main() 5 | { 6 | string s; 7 | cin>>s; 8 | int n = s.length(); 9 | int zero = 0,one=0; 10 | for(int i=0; i= 7 || one >=7){ 20 | break; 21 | } 22 | } 23 | //cout<= 7 || zero >= 7){ 25 | cout<<"YES"< 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | //freopen("input.txt","r", stdin); 11 | ll n, ones = 0, zeros = 0; 12 | string s; 13 | cin>>n>>s; 14 | for(int i=0; i 2 | int main() 3 | { 4 | int n=0,a=0,r,i; 5 | scanf("%d %d",&n,&a); 6 | for(i=1; i<=a; i++) 7 | { 8 | r=n%10; 9 | if(r==0) 10 | { 11 | n/=10; 12 | } 13 | else 14 | n-=1; 15 | } 16 | printf("%d\n",n); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /977 B. Two-gram.cpp: -------------------------------------------------------------------------------- 1 | //Bismillahir Rahmanir Rahim 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n; 12 | string s,Find; 13 | cin>>n>>s; 14 | int ans = 0; 15 | for(int i=0; i 2 | using namespace std; 3 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 4 | int main() 5 | { 6 | fastread(); 7 | int n,a[55],pos[1005]; 8 | cin>>n; 9 | for(int i=0; i>a[i]; 11 | } 12 | fill(pos,pos+1005,0); 13 | 14 | vectorv; 15 | for(int i=n-1; i>=0; i--){ 16 | if(pos[a[i]]==0){ 17 | pos[a[i]]=1; 18 | v.push_back(a[i]); 19 | } 20 | } 21 | cout<=0; i--) 25 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,del=0,l=0; 6 | string s,s1; 7 | cin>>n>>s; 8 | for(int i=0; i 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int n,_ = 0, o = 0; 12 | string s; 13 | cin>>s; 14 | n = s.length(); 15 | for(int i=0; i 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define pb push_back 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | ll n,m; 11 | mapmp; 12 | 13 | ll c,d; 14 | cin>>n; 15 | for(ll i=0; i>c>>d; 17 | mp[c] = d; 18 | } 19 | cin>>m; 20 | for(ll i=0; i>c>>d; 22 | if(mp[c] < d){ 23 | mp[c] = d; 24 | } 25 | } 26 | ll sum = 0; 27 | map:: iterator itr; 28 | for(itr=mp.begin(); itr!= mp.end(); itr++){ 29 | sum += itr->second; 30 | } 31 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | long long int a[1050]; 7 | cin>>n; 8 | for(int i=0; i>a[i]; 10 | sort(a,a+n); 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string gems[]={"purple","green","blue","orange","red","yellow"}; 6 | string names[]={"Power","Time","Space","Soul","Reality","Mind"}; 7 | mapmp; 8 | vectorv; 9 | int n,m=0; 10 | string s; 11 | cin>>n; 12 | while(n--){ 13 | cin>>s; 14 | mp[s]=1; //mark gems after scanf() 15 | } 16 | for(int i=0; i<6; i++){ 17 | if(!mp[gems[i]]){ //if mp is false than it will store which gems is need 18 | v.push_back(names[i]); 19 | } 20 | } 21 | m=v.size(); 22 | cout< 2 | using namespace std; 3 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 4 | long long int x,y; 5 | long double X,Y; 6 | int main() 7 | { 8 | fastread(); 9 | cin>>x>>y; 10 | X=y*log(x); 11 | Y=x*log(y); 12 | 13 | // cout<Y){ 18 | cout<<">\n"; 19 | } 20 | else if(X 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define pb push_back 6 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 7 | using namespace std; 8 | int main() 9 | { 10 | fastread(); 11 | int a,b,c,n,sum = 0, ans = 0; 12 | cin>>a>>b>>c>>n; 13 | sum += a - c; 14 | sum += b - c; 15 | sum += c; 16 | ans = n - sum; 17 | if(ans <= 0 || (a 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL)); 6 | using namespace std; 7 | int main() 8 | { 9 | fastread(); 10 | int n,a,zero = 0; 11 | cin>>n; 12 | 13 | sets; 14 | for(int i=0; i>a; 16 | s.insert(a); 17 | if(a == 0){ 18 | zero++; 19 | } 20 | } 21 | if(zero > 0){ 22 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,a[11],b[11]; 6 | cin>>n>>m; 7 | for(int i=0; i>a[i]; 9 | } 10 | for(int i=0; i>b[i]; 12 | } 13 | vectorv; 14 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,ans=0; 6 | int a[]={100,20,10,5,1}; 7 | cin>>n; 8 | for(int i=0; i<5; i++) 9 | { 10 | ans+=n/a[i]; 11 | n=n%a[i]; 12 | } 13 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | int n,k,c=0,pos=0,a[105]; 7 | cin>>n>>k; 8 | for(int i=0; i>a[i]; 10 | } 11 | 12 | for(int i=0; i k){ 17 | pos=i+1; 18 | break; 19 | } 20 | } 21 | if(pos>0 && pos=pos; i--){ 23 | if(a[i] <= k){ 24 | c++; 25 | } 26 | else if(a[i] > k){ 27 | break; 28 | } 29 | } 30 | } 31 | 32 | cout<