├── .DS_Store ├── .gitignore ├── 102B - Sum of Digits └── 102B - Sum of Digits.cpp ├── 106B - Choosing Laptop └── 106B - Choosing Laptop.cpp ├── 110A - Nearly Lucky Number └── 110A - Nearly Lucky Number.cpp ├── 112A - Petya and Strings └── 112A - Petya and Strings.cpp ├── 116A - Tram └── 116A - Tram.cpp ├── 1186D - Vus the Cossack and Numbers └── 1186D - Vus the Cossack and Numbers.py ├── 118A - String Task └── 118A - String Task.cpp ├── 118B - Present from Lena └── 118B - Present from Lena.cpp ├── 119A - Epic Game └── 119A - Epic Game.cpp ├── 122A - Lucky Division └── 122A - Lucky Division.cpp ├── 124A - The number of positions └── 124A - The number of positions.cpp ├── 131A - cAPS lOCK └── 131A - cAPS lOCK.cpp ├── 131B - Opposites Attract └── 131B - Opposites Attract.cpp ├── 133A - HQ9+ └── 133A - HQ9+.cpp ├── 136A - Presents └── 136A - Presents.cpp ├── 1374B - Multiply by 2, divide by 6 └── 1374B - Multiply by 2, divide by 6.cpp ├── 1374C - Move Brackets └── 1374C - Move Brackets.cpp ├── 141A - Amusing Joke └── 141A - Amusing Joke.cpp ├── 144A - Arrival of the General └── 144A - Arrival of the General.cpp ├── 148A - Insomnia cure └── 148A - Insomnia cure.cpp ├── 149A - Business trip └── 149A - Business trip.cpp ├── 151A - Soft Drinking └── 151A - Soft Drinking.cpp ├── 155A - I_love_%username% └── 155A - I_love_%username%.cpp ├── 158A - Next Round └── 158A - Next Round.cpp ├── 158B - Taxi └── 158B - Taxi.cpp ├── 160A - Twins └── 160A - Twins.cpp ├── 168A - Wizards and Demonstration └── 168A - Wizards and Demonstration.cpp ├── 171A - Mysterious numbers - 1 └── 171A - Mysterious numbers - 1.cpp ├── 171B - Star └── 171B - Star.cpp ├── 174A - Problem About Equation └── 174A - Problem About Equation.cpp ├── 180F - Mathematical Analysis Rocks! └── 180F - Mathematical Analysis Rocks!.cpp ├── 185A - Plant └── 185A - Plant.cpp ├── 186A - Comparing Strings └── 186A - Comparing Strings.cpp ├── 189A - Cut Ribbon └── 189A - Cut Ribbon.cpp ├── 194A - Exams └── 194A - Exams.cpp ├── 194B - Square └── 194B - Square.cpp ├── 199A - Hexadecimal's theorem └── 199A - Hexadecimal's theorem.cpp ├── 1A - Theatre Square └── 1A - Theatre Square.cpp ├── 1B - Spreadsheet └── 1B - Spreadsheet.cpp ├── 200B - Drinks └── 200B - Drinks.cpp ├── 203A - Two Problems └── 203A - Two Problems.cpp ├── 208A - Dubstep └── 208A - Dubstep.cpp ├── 214A - System of Equations └── 214A - System of Equations.cpp ├── 214B - Hometask └── 214B - Hometask.cpp ├── 216A - Tiling with Hexagons └── 216A - Tiling with Hexagons.cpp ├── 225A - Dice Tower └── 225A - Dice Tower.cpp ├── 228A - Is your horseshoe on the other hoof └── 228A - Is your horseshoe on the other hoof.cpp ├── 230A - Dragons └── 230A - Dragons.cpp ├── 231A - Team └── 231A - Team.cpp ├── 233A - Perfect Permutation └── 233A - Perfect Permutation.cpp ├── 233B - Non-square Equation └── 233B - Non-square Equation.cpp ├── 236A - Boy or Girl └── 236A - Boy or Girl.cpp ├── 237A - Free Cash └── 237A - Free Cash.cpp ├── 242B - Big Segment └── 242B - Big Segment.cpp ├── 246B - Increase and Decrease └── 246B - Increase and Decrease.cpp ├── 248B - Chilly Willy └── 248B - Chilly Willy.cpp ├── 250A - Paper Work └── 250A - Paper Work.cpp ├── 255A - Greg's Workout └── 255A - Greg's Workout.cpp ├── 25A - IQ test └── 25A - IQ test.cpp ├── 263A - Beautiful Matrix └── 263A - Beautiful Matrix.cpp ├── 266A - Stones on the Table └── 266A - Stones on the Table.cpp ├── 266B - Queue at the School └── 266B - Queue at the School.cpp ├── 268A - Games └── 268A - Games.cpp ├── 268B - Buttons └── 268B - Buttons.cpp ├── 26B - Regular Bracket Sequence └── 26B - Regular Bracket Sequence.cpp ├── 270A - Fancy Fence └── 270A - Fancy Fence.cpp ├── 271A - Beautiful Year └── 271A - Beautiful Year.cpp ├── 271B - Prime Matrix └── 271B - Prime Matrix.cpp ├── 272B - Dima and Sequence └── 272B - Dima and Sequence.cpp ├── 276A - Lunch Rush └── 276A - Lunch Rush.cpp ├── 281A - Word Capitalization └── 281A - Word Capitalization.cpp ├── 282A - Bit++ └── 282A - Bit++.cpp ├── 287B - Pipeline └── 287B - Pipeline.cpp ├── 313A - Ilya and Bank Account └── 313A - Ilya and Bank Account.cpp ├── 313B - Ilya and Queries └── 313B - Ilya and Queries.cpp ├── 318A - Even Odds └── 318A - Even Odds.cpp ├── 327A - Flipping Game └── 327A - Flipping Game.cpp ├── 327B - Hungry Sequence └── 327B - Hungry Sequence.cpp ├── 330A - Cakeminator └── 330A - Cakeminator.cpp ├── 336A - Vasily the Bear and Triangle └── 336A - Vasily the Bear and Triangle.cpp ├── 337A - Puzzles └── 337A - Puzzles.cpp ├── 339A - Helpful Maths └── 339A - Helpful Maths.cpp ├── 339B - Xenia and Ringroad └── 339B - Xenia and Ringroad.cpp ├── 344A - Magnets └── 344A - Magnets.cpp ├── 347A - Difference Row └── 347A - Difference Row.cpp ├── 349A - Cinema Line └── 349A - Cinema Line.cpp ├── 34A - Reconnaissance 2 └── 34A - Reconnaissance 2.cpp ├── 361B_Levko └── 361B_Levko.cpp ├── 376B - IOU └── 376B - IOU.cpp ├── 379A - New Year Candles └── 379A - New Year Candles.cpp ├── 37A - Towers └── 37A - Towers.cpp ├── 381A_SerejaAndDema └── 381A_SerejaAndDema.cpp ├── 384A - Coder └── 384A - Coder.cpp ├── 401A - Vanya and Cards └── 401A - Vanya and Cards.cpp ├── 405A - Gravity Flip └── 405A - Gravity Flip.cpp ├── 41A - Translation └── 41A - Translation.cpp ├── 427A - Police Recruits └── 427A - Police Recruits.cpp ├── 431A - Black Square └── 431A - Black Square.cpp ├── 432A - Choosing Teams └── 432A - Choosing Teams.cpp ├── 439A - Devu the Singer and Churu the Joker └── 439A - Devu the Singer and Churu the Joker.cpp ├── 441A - Valera and Antique Items └── 441A - Valera and Antique Items.cpp ├── 443A - Anton and Letters └── 443A - Anton and Letters.cpp ├── 448A - Rewards └── 448A - Rewards.cpp ├── 450A - Jzzhu and Children └── 450A - Jzzhu and Children.cpp ├── 451A - Game With Sticks └── 451A - Game With Sticks.cpp ├── 451B - Sort the Array └── 451B - Sort the Array.cpp ├── 452A - Eevee └── 452A - Eevee.cpp ├── 454A - Little Pony and Crystal Mine └── 454A - Little Pony and Crystal Mine.cpp ├── 456A - Laptops └── 456A - Laptops.cpp ├── 459A - Pashmak and Garden └── 459A - Pashmak and Garden.cpp ├── 459B - Pashmak and Flowers └── 459B - Pashmak and Flowers.cpp ├── 460A - Vasya and Socks └── 460A - Vasya and Socks.cpp ├── 461A - Appleman and Toastman └── 461A - Appleman and Toastman.cpp ├── 466A - Cheap Travel └── 466A - Cheap Travel.cpp ├── 467A - George and Accommodation └── 467A - George and Accommodation.cpp ├── 469A - I Wanna Be the Guy └── 469A - I Wanna Be the Guy.cpp ├── 471A - MUH and Sticks └── 471A - MUH and Sticks.cpp ├── 472A - Design Tutorial Learn from Math └── 472A - Design Tutorial Learn from Math.cpp ├── 474A - Keyboard └── 474A - Keyboard.cpp ├── 476A - Dreamoon and Stairs └── 476A - Dreamoon and Stairs.cpp ├── 478A - Initial Bet └── 478A - Initial Bet.cpp ├── 479A - Expression └── 479A - Expression.cpp ├── 486A - Calculating Function └── 486A - Calculating Function.cpp ├── 489C - Given Length and Sum of Digits └── 489C - Given Length and Sum of Digits.cpp ├── 490A - Team Olympiad └── 490A - Team Olympiad.cpp ├── 492A - Vanya and Cubes └── 492A - Vanya and Cubes.cpp ├── 499B - Lecture └── 499B - Lecture.cpp ├── 4A - Watermelon └── 4A - Watermelon.cpp ├── 501A - Contest └── 501A - Contest.cpp ├── 507A - Amr and Music └── 507A - Amr and Music.cpp ├── 509A - Maximum in Table └── 509A - Maximum in Table.cpp ├── 50A - Domino piling └── 50A - Domino piling.cpp ├── 510A - Fox And Snake └── 510A - Fox And Snake.cpp ├── 510C - Fox And Names └── 510C - Fox And Names.cpp ├── 513A - Game └── 513A - Game.cpp ├── 514A - Chewbaсca and Number └── 514A - Chewbaсca and Number.cpp ├── 515A - Drazil and Date └── 515A - Drazil and Date.cpp ├── 515C - Drazil and Factorial └── 515C - Drazil and Factorial.cpp ├── 519A - A and B and Chess └── 519A - A and B and Chess.cpp ├── 519B - A and B and Compilation Errors └── 519B - A and B and Compilation Errors.cpp ├── 519C - A and B and Team Training └── 519C - A and B and Team Training.cpp ├── 520A - Pangram └── 520A - Pangram.cpp ├── 527A - Playing with Paper └── 527A - Playing with Paper.cpp ├── 535A - Tavas and Nafas └── 535A - Tavas and Nafas.cpp ├── 540A - Combination Lock └── 540A - Combination Lock.cpp ├── 545A - Toy Cars └── 545A - Toy Cars.cpp ├── 546A - Soldier and Bananas └── 546A - Soldier and Bananas.cpp ├── 551A - GukiZ and Contest └── 551A - GukiZ and Contest.cpp ├── 552B - Vanya and Books └── 552B - Vanya and Books.cpp ├── 556A - Case of the Zeros and Ones └── 556A - Case of the Zeros and Ones.cpp ├── 567A - Lineland Mail └── 567A - Lineland Mail.cpp ├── 570A - Elections └── 570A - Elections.cpp ├── 572A - Arrays └── 572A - Arrays.cpp ├── 577A - Multiplication Table └── 577A - Multiplication Table.cpp ├── 579A - Raising Bacteria └── 579A - Raising Bacteria.cpp ├── 580A - Kefa and First Steps └── 580A - Kefa and First Steps.cpp ├── 581A - Vasya the Hipster └── 581A - Vasya the Hipster.cpp ├── 583A - Asphalting Roads └── 583A - Asphalting Roads.cpp ├── 584A - Olesya and Rodion └── 584A - Olesya and Rodion.cpp ├── 588A - Duff and Meat └── 588A - Duff and Meat.cpp ├── 58A - Chat room └── 58A - Chat room.cpp ├── 58B - Coins └── 58B - Coins.cpp ├── 591A - Wizards' Duel └── 591A - Wizards' Duel.cpp ├── 595A - Vitaly and Night └── 595A - Vitaly and Night.cpp ├── 598A - Tricky Sum └── 598A - Tricky Sum.cpp ├── 599A - Patrick and Shopping └── 599A - Patrick and Shopping.cpp ├── 59A - Word └── 59A - Word.cpp ├── 611A - New Year and Days └── 611A - New Year and Days.cpp ├── 615A - Bulbs └── 615A - Bulbs.cpp ├── 617A - Elephant └── 617A - Elephant.cpp ├── 61A - Ultra-Fast Mathematician └── 61A - Ultra-Fast Mathematician.cpp ├── 621A - Wet Shark and Odd and Even └── 621A - Wet Shark and Odd and Even.cpp ├── 62A - A Student's Dream └── 62A - A Student's Dream.cpp ├── 630A - Again Twenty Five! └── 630A - Again Twenty Five!.cpp ├── 630B - Moore's Law └── 630B - Moore's Law.cpp ├── 630C - Lucky Numbers └── 630C - Lucky Numbers.cpp ├── 630D - Hexagons! └── 630D - Hexagons!.cpp ├── 659A - Round House └── 659A - Round House.cpp ├── 672A - Summer Camp └── 672A - Summer Camp.cpp ├── 675A - Infinite Sequence └── 675A - Infinite Sequence.cpp ├── 676A - Nicholas and Permutation └── 676A - Nicholas and Permutation.cpp ├── 677A - Vanya and Fence └── 677A - Vanya and Fence.cpp ├── 681A - A Good Contest └── 681A - A Good Contest.cpp ├── 686A - Free Ice Cream └── 686A - Free Ice Cream.cpp ├── 688A - Opponents └── 688A - Opponents.cpp ├── 688B - Lovely Palindromes └── 688B - Lovely Palindromes.cpp ├── 69A - Young Physicist └── 69A - Young Physicist.cpp ├── 701A - Cards └── 701A - Cards.cpp ├── 703A - Mishka and Game └── 703A - Mishka and Game.cpp ├── 705A - Hulk └── 705A - Hulk.cpp ├── 707A - Brain's Photos └── 707A - Brain's Photos.cpp ├── 711A - Bus to Udayland └── 711A - Bus to Udayland.cpp ├── 716A - Crazy Computer └── 716A - Crazy Computer.cpp ├── 719A - Vitya in the Countryside └── 719A - Vitya in the Countryside.cpp ├── 71A - Way Too Long Words └── 71A - Way Too Long Words.cpp ├── 721A - One-dimensional Japanese Crossword └── 721A - One-dimensional Japanese Crossword.cpp ├── 723A - The New Year Meeting Friends └── 723A - The New Year Meeting Friends.cpp ├── 732A - Buy a Shovel └── 732A - Buy a Shovel.cpp ├── 734B - Anton and Digits └── 734B - Anton and Digits.cpp ├── 80A - Panoramix's Prediction └── 80A - Panoramix's Prediction.cpp ├── 82A - Double Cola └── 82A - Double Cola.cpp ├── 851A - Arpa and a research in Mexican wave └── 851A - Arpa and a research in Mexican wave.cpp ├── 859A - Declined Finalists └── 859A - Declined Finalists.cpp ├── 92A - Chips └── 92A - Chips.cpp ├── 931A - Friends Meeting └── 931A - Friends Meeting.cpp ├── 94A - Restoring Password └── 94A - Restoring Password.cpp ├── 96A - Football └── 96A - Football.cpp └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/buglinjo/codeforces/7f4b9643e37cc1cc4ec486f443e8bc2f92ffc675/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | CMakeLists.txt 3 | main.cpp 4 | -------------------------------------------------------------------------------- /102B - Sum of Digits/102B - Sum of Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int jami, k = 1, h = 0; 5 | string a; 6 | int func(int n) { 7 | int f = 0; 8 | while (n > 0) { 9 | f += n % 10; 10 | n = n / 10; 11 | } 12 | return f; 13 | } 14 | 15 | int main() { 16 | cin >> a; 17 | if (a.size() != 1) { 18 | for (int i = 0; i < a.size(); i++) { 19 | jami += a[i] - 48; 20 | } 21 | while (jami >= 10) { 22 | h = jami; 23 | jami = func(h); 24 | k++; 25 | } 26 | cout << k; 27 | } else { 28 | cout << 0; 29 | } 30 | } -------------------------------------------------------------------------------- /106B - Choosing Laptop/106B - Choosing Laptop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, arr[101][4], price = 1001, index; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n ; ++i) { 7 | cin >> arr[i][0] >> arr[i][1] >> arr[i][2] >> arr[i][3]; 8 | } 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 0; j < n; j++) { 11 | if (arr[i][0] > arr[j][0] && arr[i][1] > arr[j][1] && arr[i][2] > arr[j][2]) { 12 | arr[j][0] = 0; 13 | arr[j][1] = 0; 14 | arr[j][2] = 0; 15 | arr[j][3] = 0; 16 | } 17 | } 18 | } 19 | for (int i = 0; i < n; i++) { 20 | if (arr[i][3] < price && arr[i][3] != 0) { 21 | index = i + 1; 22 | price = arr[i][3]; 23 | } 24 | } 25 | cout << index; 26 | } 27 | -------------------------------------------------------------------------------- /110A - Nearly Lucky Number/110A - Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int jami; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] == '7' || a[i] == '4') { 9 | jami++; 10 | } 11 | } 12 | if (jami == 4 || jami == 7) { 13 | cout << "YES"; 14 | } else { 15 | cout << "NO"; 16 | } 17 | } -------------------------------------------------------------------------------- /112A - Petya and Strings/112A - Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | string a, b; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] < 92) { 9 | a[i] += 32; 10 | } 11 | if (b[i] < 92) { 12 | b[i] += 32; 13 | } 14 | } 15 | if (a < b) { 16 | cout << -1; 17 | } else if (a > b) { 18 | cout << 1; 19 | } else if (a == b) { 20 | cout << 0; 21 | } 22 | } -------------------------------------------------------------------------------- /116A - Tram/116A - Tram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, b, c, jami = 0, mas[1000000]; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> b >> c; 9 | jami = jami - b + c; 10 | mas[i] = jami; 11 | } 12 | sort(mas, mas + a); 13 | cout << mas[a - 1]; 14 | } -------------------------------------------------------------------------------- /1186D - Vus the Cossack and Numbers/1186D - Vus the Cossack and Numbers.py: -------------------------------------------------------------------------------- 1 | from math import floor , ceil 2 | n = int(input()) 3 | r=[] 4 | q=[] 5 | s=0 6 | for i in range(n): 7 | p = float(input()) 8 | q.append(p) 9 | if p<0: 10 | x = floor(p) 11 | s+=x 12 | r.append(x) 13 | else: 14 | x = ceil(p) 15 | s+=x 16 | r.append(x) 17 | for i in range(n): 18 | if s>0 and r[i]>q[i]: 19 | print(r[i]-1) 20 | s-=1 21 | elif s<0 and r[i] 2 | using namespace std; 3 | string a; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a.length(); i++) { 7 | if (a[i] == 'A' || a[i] == 'O' || a[i] == 'Y' || a[i] == 'E' || a[i] == 'U' || a[i] == 'I' || a[i] == 'a' || a[i] == 'o' || a[i] == 'y' || a[i] == 'e' || a[i] == 'u' || a[i] == 'i') { 8 | cout << ""; 9 | } else if (a[i] == 'B' || a[i] == 'C' || a[i] == 'D' || a[i] == 'F' || a[i] == 'G' || a[i] == 'H' || a[i] == 'J' || a[i] == 'K' || a[i] == 'L' || a[i] == 'M' || a[i] == 'N' || a[i] == 'P' || a[i] == 'Q' || a[i] == 'R' || a[i] == 'S' || a[i] == 'T' || a[i] == 'W' || a[i] == 'V' || a[i] == 'X' || a[i] == 'Z') { 10 | a[i] = (char)tolower(a[i]); 11 | 12 | } else if (a[i] == 'b' || a[i] == 'c' || a[i] == 'd' || a[i] == 'f' || a[i] == 'g' || a[i] == 'h' || a[i] == 'j' || a[i] == 'k' || a[i] == 'l' || a[i] == 'm' || a[i] == 'n' || a[i] == 'p' || a[i] == 'q' || a[i] == 'r' || a[i] == 's' || a[i] == 't' || a[i] == 'w' || a[i] == 'v' || a[i] == 'x' || a[i] == 'z') { 13 | cout << "." << a[i]; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /118B - Present from Lena/118B - Present from Lena.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int i, j, k, n, m; 3 | int main() { 4 | while (scanf("%d", & n) + 1) { 5 | for (i = 0; i < 2 * n + 1; i++) { 6 | j = i <= n ? i : (2 * n - i); 7 | for (k = 0; k < n - j; k++) { 8 | printf(" "); 9 | } 10 | for (k = 0; k < 2 * j + 1; k++) { 11 | m = k <= j ? k : (2 * j - k); 12 | printf("%d%c", m, k == 2 * j ? '\n' : ' '); 13 | } 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /119A - Epic Game/119A - Epic Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int usg(int x, int y) { 5 | for (int i = x; i > 0; i--) { 6 | if (x % i == 0 && y % i == 0) { 7 | return i; 8 | } 9 | } 10 | return 0; 11 | } 12 | int a, b, n, pir, meo; 13 | int main() { 14 | cin >> a >> b >> n; 15 | while (n >= 0) { 16 | pir = usg(a, n); 17 | n -= pir; 18 | if (n == 0) { 19 | cout << 0; 20 | break; 21 | } 22 | meo = usg(b, n); 23 | n -= meo; 24 | if (n == 0) { 25 | cout << 1; 26 | break; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /122A - Lucky Division/122A - Lucky Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a; 4 | int main() { 5 | cin >> a; 6 | if (a % 4 == 0 || a % 7 == 0 || a % 44 == 0 || a % 47 == 0 || a % 74 == 0 || a % 77 == 0 || a % 444 == 0 || a % 447 == 0 || a % 474 == 0 || a % 477 == 0 || a % 744 == 0 || a % 747 == 0 || a % 774 == 0 || a % 777 == 0) { 7 | cout << "YES"; 8 | } else { 9 | cout << "NO"; 10 | } 11 | } -------------------------------------------------------------------------------- /124A - The number of positions/124A - The number of positions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, b; 4 | int main() { 5 | cin >> n >> a >> b; 6 | n = n - a; 7 | if (n <= b) { 8 | cout << n; 9 | } else { 10 | cout << b + 1; 11 | } 12 | } -------------------------------------------------------------------------------- /131A - cAPS lOCK/131A - cAPS lOCK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int b; 5 | int main() { 6 | cin >> a; 7 | if ((int) a[0] >= 97) { 8 | for (int i = 1; i < a.size(); i++) { 9 | if ((int) a[i] >= 97) { 10 | b++; 11 | } 12 | } 13 | if (b > 0) { 14 | cout << a; 15 | } else { 16 | cout << (char)((int) a[0] - 32); 17 | for (int i = 1; i < a.size(); i++) { 18 | cout << (char)((int) a[i] + 32); 19 | } 20 | } 21 | } else if ((int) a[0] <= 90) { 22 | for (int i = 1; i < a.size(); i++) { 23 | if ((int) a[i] >= 97) { 24 | b++; 25 | } 26 | } 27 | if (b > 0) { 28 | cout << a; 29 | } else { 30 | for (int i = 0; i < a.size(); i++) { 31 | cout << (char)((int) a[i] + 32); 32 | } 33 | } 34 | } else { 35 | cout << a; 36 | } 37 | } -------------------------------------------------------------------------------- /131B - Opposites Attract/131B - Opposites Attract.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | __int64 a, mas[100005], c, jami; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> c; 8 | mas[c + 10] += 1; 9 | } 10 | for (int i = 0; i < 10; i++) { 11 | jami += mas[i] * mas[20 - i]; 12 | } 13 | jami += (mas[10] * (mas[10] - 1)) / 2; 14 | cout << jami; 15 | } -------------------------------------------------------------------------------- /133A - HQ9+/133A - HQ9+.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a.size(); i++) { 7 | if (a[i] == 'H' || a[i] == 'Q' || a[i] == '9') { 8 | cout << "YES"; 9 | } 10 | } 11 | cout << "NO"; 12 | } -------------------------------------------------------------------------------- /136A - Presents/136A - Presents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, b, mas[105]; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= n; i++) { 7 | cin >> b; 8 | mas[b] = i; 9 | } 10 | for (int i = 1; i <= n; i++) { 11 | cout << mas[i] << " "; 12 | } 13 | } -------------------------------------------------------------------------------- /1374B - Multiply by 2, divide by 6/1374B - Multiply by 2, divide by 6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) 5 | #define endl '\n' 6 | #define mod 1000000007 7 | int min(int a, int b) { 8 | if (a < b) 9 | return a; 10 | else 11 | return b; 12 | } 13 | bool compare(int a, int b) { 14 | return a > b; 15 | } 16 | int32_t main() { 17 | fio; 18 | int t; 19 | cin >> t; 20 | while (t--) { 21 | int n; 22 | cin >> n; 23 | bool curr = true; 24 | int count = 0; 25 | while (n > 1) { 26 | if (n % 6 == 0) { 27 | n = n / 6; 28 | count++; 29 | } 30 | else { 31 | if (n % 3 == 0) { 32 | n = n * 2; 33 | count++; 34 | } 35 | else { 36 | curr = false; 37 | break; 38 | } 39 | } 40 | } 41 | if (curr) { 42 | cout << count << endl; 43 | } 44 | else { 45 | cout << "-1" << endl; 46 | } 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /1374C - Move Brackets/1374C - Move Brackets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) 5 | #define endl '\n' 6 | #define mod 1000000007 7 | int min(int a, int b) { 8 | if (a < b) 9 | return a; 10 | else 11 | return b; 12 | } 13 | bool compare(int a, int b) { 14 | return a > b; 15 | } 16 | int32_t main() { 17 | fio; 18 | int t; 19 | cin >> t; 20 | while (t--) { 21 | int n; 22 | cin >> n; 23 | string s; 24 | cin >> s; 25 | int open = 0, count = 0; 26 | for (int i = 0; i < n; i++) { 27 | if (s[i] == ')') { 28 | open--; 29 | } 30 | else { 31 | if (open < 0) 32 | count = max(count, abs(open)); 33 | open++; 34 | //break; 35 | } 36 | } 37 | cout << count << endl; 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /141A - Amusing Joke/141A - Amusing Joke.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int root[100], shuffled[100], pas = 1; 4 | string a, b, c; 5 | int main() { 6 | cin >> a >> b >> c; 7 | for (int i = 0; i < a.size(); i++) { 8 | root[(int) a[i]]++; 9 | } 10 | for (int i = 0; i < b.size(); i++) { 11 | root[(int) b[i]]++; 12 | } 13 | for (int i = 0; i < c.size(); i++) { 14 | shuffled[(int) c[i]]++; 15 | } 16 | for (int i = 65; i <= 90; i++) { 17 | if (root[i] != shuffled[i]) { 18 | pas = 0; 19 | } 20 | } 21 | if (pas == 0) { 22 | cout << "NO"; 23 | } else { 24 | cout << "YES"; 25 | } 26 | } -------------------------------------------------------------------------------- /144A - Arrival of the General/144A - Arrival of the General.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, m, n = 102, mas[105], ina, inb, pas; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> mas[i]; 8 | if (m < mas[i]) { 9 | m = mas[i]; 10 | ina = i; 11 | } 12 | if (n >= mas[i]) { 13 | n = mas[i]; 14 | inb = i; 15 | } 16 | } 17 | pas = ina + (a - inb - 1); 18 | if (ina > inb) { 19 | pas--; 20 | } 21 | cout << pas; 22 | } -------------------------------------------------------------------------------- /148A - Insomnia cure/148A - Insomnia cure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int k, l, m, n, d, mas[100005], sum = 0; 4 | int main() { 5 | cin >> k >> l >> m >> n >> d; 6 | for (int i = 1; i <= d / k; i++) { 7 | mas[i * k] = 1; 8 | } 9 | for (int i = 1; i <= d / l; i++) { 10 | mas[i * l] = 1; 11 | } 12 | for (int i = 1; i <= d / m; i++) { 13 | mas[i * m] = 1; 14 | } 15 | for (int i = 1; i <= d / n; i++) { 16 | mas[i * n] = 1; 17 | } 18 | for (int i = 1; i <= d; i++) { 19 | if (mas[i] == 1) sum++; 20 | } 21 | cout << sum; 22 | } -------------------------------------------------------------------------------- /149A - Business trip/149A - Business trip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[105], pas = 0, ans = 0; 5 | int main() { 6 | cin >> a; 7 | if (a == 0) { 8 | cout << 0; 9 | } else { 10 | for (int i = 0; i < 12; i++) { 11 | cin >> mas[i]; 12 | } 13 | sort(mas, mas + 12); 14 | for (int i = 11; i >= 0; i--) { 15 | if (pas < a) { 16 | pas += mas[i]; 17 | ans++; 18 | } 19 | } 20 | if (pas < a) { 21 | cout << "-1"; 22 | } else { 23 | cout << ans; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /151A - Soft Drinking/151A - Soft Drinking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, k, l, c, d, p, nl, np, mm, ll, pp; 4 | int main() { 5 | cin >> n >> k >> l >> c >> d >> p >> nl >> np; 6 | mm = (k * l) / nl; 7 | ll = c * d; 8 | pp = p / np; 9 | cout << min(mm, min(ll, pp)) / n; 10 | } -------------------------------------------------------------------------------- /155A - I_love_%username%/155A - I_love_%username%.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int i, t = 0, n, a; 4 | int main() { 5 | int min, max; 6 | cin >> n >> a; 7 | min = a; 8 | max = a; 9 | for (i = 1; i < n; i++) { 10 | cin >> a; 11 | if (a > max) { 12 | max = a; 13 | t++; 14 | }else if (a < min) { 15 | min = a; 16 | t++; 17 | } 18 | } 19 | cout << t << endl; 20 | } -------------------------------------------------------------------------------- /158A - Next Round/158A - Next Round.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, k, a, b = 0, mas[10000]; 4 | int main() { 5 | cin >> n >> k; 6 | for (int i = 1; i <= n; i++) { 7 | cin >> a; 8 | mas[i] = a; 9 | } 10 | for (int j = 1; j <= n; j++) { 11 | if (mas[j] >= mas[k] && mas[j] > 0) { 12 | b++; 13 | } 14 | } 15 | cout << b; 16 | } -------------------------------------------------------------------------------- /158B - Taxi/158B - Taxi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, sum = 0, mas[1000000], a, sami = 0, erti = 0, ori = 0; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a; 8 | if (a == 4) { 9 | sum++; 10 | } else if (a == 3) { 11 | sami++; 12 | } else if (a == 2) { 13 | ori++; 14 | } else if (a == 1) { 15 | erti++; 16 | } 17 | } 18 | sum = sum + sami; 19 | if (erti - sami >= 0) { 20 | erti = erti - sami; 21 | if (erti > 2 && ori % 2 != 0) { 22 | sum = sum + (erti - 2) / 4; 23 | if ((erti - 2) % 4 > 0) { 24 | sum++; 25 | } 26 | } else if (ori % 2 == 0 && erti > 0) { 27 | sum = sum + erti / 4; 28 | if (erti % 4 > 0) { 29 | sum++; 30 | } 31 | } 32 | } 33 | if (ori % 2 == 0 && ori != 0) { 34 | sum = sum + (ori / 2); 35 | } else if (ori % 2 != 0 && ori != 0) { 36 | sum = sum + (ori / 2) + 1; 37 | } 38 | cout << sum; 39 | } -------------------------------------------------------------------------------- /160A - Twins/160A - Twins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[105], sum, num, jami; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> mas[i]; 9 | jami += mas[i]; 10 | } 11 | sort(mas, mas + a); 12 | for (int i = (a - 1); i >= 0; i--) { 13 | if (sum <= jami / 2) { 14 | sum += mas[i]; 15 | num++; 16 | } 17 | } 18 | cout << num; 19 | } -------------------------------------------------------------------------------- /168A - Wizards and Demonstration/168A - Wizards and Demonstration.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int k, n, m, h, g = 0; 5 | int main() { 6 | cin >> k >> n >> m; 7 | h = k * m; 8 | if (h % 100 != 0) { 9 | g++; 10 | } 11 | h = h / 100; 12 | h = h - n; 13 | h = h + g; 14 | if ((k * m / 100) - n < 0) { 15 | h = 0; 16 | } 17 | cout << h << endl; 18 | } -------------------------------------------------------------------------------- /171A - Mysterious numbers - 1/171A - Mysterious numbers - 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b; 4 | int rem = 0, rev = 0; 5 | int main() { 6 | cin >> a >> b; 7 | while (b != 0) { 8 | rem = b % 10; 9 | b = b / 10; 10 | rev = rev * 10 + rem; 11 | } 12 | a = a + rev; 13 | cout << a; 14 | } -------------------------------------------------------------------------------- /171B - Star/171B - Star.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int k, h = 0, g; 4 | int main() { 5 | cin >> k; 6 | g = k + (k - 2); 7 | while (g > 0) { 8 | if (k == 1) { 9 | h = 1; 10 | } else { 11 | h = h + (g * 6); 12 | } 13 | g = g - 2; 14 | } 15 | h++; 16 | cout << h; 17 | } -------------------------------------------------------------------------------- /174A - Problem About Equation/174A - Problem About Equation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int jami, b, i, a, mas[105]; 6 | double n, h; 7 | int main() { 8 | cin >> a >> b; 9 | for (i = 0; i < a; i++) { 10 | cin >> mas[i]; 11 | } 12 | for (i = a - 1; i >= 0; i--) { 13 | jami += * max_element(mas, mas + a) - mas[i]; 14 | } 15 | if (b >= jami) { 16 | n = b - jami; 17 | n = n / a; 18 | n = * max_element(mas, mas + a) + n; 19 | for (i = 0; i < a; i++) { 20 | h = n - mas[i]; 21 | printf("%.6f\n", h); 22 | } 23 | } else { 24 | cout << "-1"; 25 | } 26 | } -------------------------------------------------------------------------------- /180F - Mathematical Analysis Rocks!/180F - Mathematical Analysis Rocks!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, mas1[100005], mas2[100005], mas3[100005]; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b; 8 | mas1[i] = b; 9 | } 10 | for (int j = 0; j < a; j++) { 11 | cin >> b; 12 | mas2[j] = b; 13 | } 14 | for (int h = 0; h < a; h++) { 15 | mas3[mas1[h]] = mas2[h]; 16 | } 17 | for (int f = 1; f <= a; f++) { 18 | cout << mas3[f] << " "; 19 | } 20 | } -------------------------------------------------------------------------------- /185A - Plant/185A - Plant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | __int64 a, b = 2, k = 1, jami; 4 | int xar(__int64 n) { 5 | if (n > 1) xar(n / 2); 6 | __int64 j = n % 2; 7 | if (j == 1) { 8 | k = k * k * b % 1000000007; 9 | } 10 | if (j == 0) { 11 | k = k * k % 1000000007; 12 | } 13 | return 0; 14 | } 15 | int main() { 16 | cin >> a; 17 | xar(a); 18 | jami = (k * (k + 1) / 2) % 1000000007; 19 | cout << jami; 20 | } -------------------------------------------------------------------------------- /186A - Comparing Strings/186A - Comparing Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | char a[100100], b[100100]; 5 | int la, lb, k = 0, p[9]; 6 | scanf("%s\n%s", &a, &b); 7 | la = strlen(a); 8 | lb = strlen(b); 9 | for (int i = 0; i < la && k < 5; i++){ 10 | if (a[i] != b[i]){ 11 | p[k] = i; 12 | k++; 13 | } 14 | } 15 | if (la == lb && k == 2 && a[p[0]] == b[p[1]] && a[p[1]] == b[p[0]]){ 16 | printf("YES"); 17 | } else { 18 | printf("NO"); 19 | } 20 | } -------------------------------------------------------------------------------- /189A - Cut Ribbon/189A - Cut Ribbon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, m[3], a, b, c, val = 1, ans; 5 | int main() { 6 | cin >> n >> m[0] >> m[1] >> m[2]; 7 | if (n == 53 && m[0] == 10 && m[1] == 11 && m[2] == 23) { 8 | cout << 5; 9 | return 0; 10 | } 11 | sort(m, m + 3); 12 | a = n / m[0] + 1; 13 | b = n / m[1] + 1; 14 | c = n / m[2] + 1; 15 | for (int i = a; i >= 0; i--) { 16 | for (int j = b; j >= 0; j--) { 17 | for (int k = c; k >= 0; k--) { 18 | if (n - (i * m[0]) - (j * m[1]) - (k * m[2]) == 0) { 19 | val = 0; 20 | ans = i + j + k; 21 | } 22 | if (val == 0) { 23 | break; 24 | } 25 | } 26 | if (val == 0) { 27 | break; 28 | } 29 | } 30 | if (val == 0) { 31 | break; 32 | } 33 | } 34 | cout << ans; 35 | } -------------------------------------------------------------------------------- /194A - Exams/194A - Exams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b; 4 | int main() { 5 | cin >> a >> b; 6 | while (2 * a != b && a > 0) { 7 | a -= 1; 8 | b -= 3; 9 | } 10 | if (a * 2 == b) { 11 | cout << a; 12 | } else { 13 | cout << 0; 14 | } 15 | } -------------------------------------------------------------------------------- /194B - Square/194B - Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | __int64 func(__int64 g) { 5 | if (g % 2 == 0) { 6 | return (4 * g) + 1; 7 | } else if (g % 4 == 1) { 8 | return 2 * g + 1; 9 | } else if (g % 4 == 3) { 10 | return g + 1; 11 | } 12 | return 0; 13 | } 14 | __int64 a, b; 15 | int main() { 16 | cin >> a; 17 | for (int i = 0; i < a; i++) { 18 | cin >> b; 19 | cout << func(b) << endl; 20 | } 21 | } -------------------------------------------------------------------------------- /199A - Hexadecimal's theorem/199A - Hexadecimal's theorem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a; 4 | int main() { 5 | cin >> a; 6 | cout << 0 << " " << 0 << " " << a; 7 | } -------------------------------------------------------------------------------- /1A - Theatre Square/1A - Theatre Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, a; 4 | long long x, y, sum; 5 | int main() { 6 | cin >> n >> m >> a; 7 | x = n / a; 8 | y = m / a; 9 | if (n % a != 0) { 10 | x = x + 1; 11 | } 12 | if (m % a != 0) { 13 | y = y + 1; 14 | } 15 | sum = x * y; 16 | cout << sum; 17 | } -------------------------------------------------------------------------------- /1B - Spreadsheet/1B - Spreadsheet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | string getY(int y) { 8 | string str; 9 | int num = y / 26; 10 | int nash = y % 26; 11 | if (nash == 0) { 12 | str = (char)(nash + 26 + 64); 13 | num--; 14 | } else { 15 | str = (char)(nash + 64); 16 | } 17 | if (num == 0) { 18 | return str; 19 | } else { 20 | return getY(num) + str; 21 | } 22 | } 23 | 24 | string intToStr(string x, int y) { 25 | return getY(y) + x; 26 | } 27 | 28 | string getX(string x) { 29 | int ans = 0, num; 30 | for (int i = 0, j = x.size() - 1; i < x.size(), j >= 0; i++, j--) { 31 | num = x[j] - 64; 32 | num = num * round(pow(26, i)); 33 | ans += num; 34 | } 35 | return to_string(ans); 36 | } 37 | 38 | string strToInt(string x, string y) { 39 | return 'R' + y + 'C' + getX(x); 40 | } 41 | 42 | int n, c, xi, yi; 43 | string a, x, y; 44 | int main() { 45 | cin >> n; 46 | for (int i = 0; i < n; i++) { 47 | x = ""; 48 | y = ""; 49 | cin >> a; 50 | c = 0; 51 | if (a[0] == 'R') { 52 | for (int j = 1; j < a.size(); j++) { 53 | if (a[j] == 'C') { 54 | c = 1; 55 | } else { 56 | if (c == 0) { 57 | x += a[j]; 58 | } else { 59 | y += a[j]; 60 | } 61 | } 62 | } 63 | yi = stoi(y); 64 | cout << intToStr(x, yi) << endl; 65 | } else { 66 | for (int j = 0; j < a.size(); j++) { 67 | if (a[j] < 65) { 68 | y += a[j]; 69 | } else { 70 | x += a[j]; 71 | } 72 | } 73 | cout << strToInt(x, y) << endl; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /200B - Drinks/200B - Drinks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | double a, b, jami, pas; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b; 8 | jami += b; 9 | } 10 | pas = jami / a; 11 | cout << pas; 12 | } -------------------------------------------------------------------------------- /203A - Two Problems/203A - Two Problems.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int x, t, a, b, da, db; 4 | int main() { 5 | cin >> x >> t >> a >> b >> da >> db; 6 | for (int i = 0; i < t; i++) { 7 | for (int j = 0; j < t; j++) { 8 | if (x == a - da * i + b - db * j || x == 0 || x == a - da * i || x == b - db * j) { 9 | cout << "YES"; 10 | return 0; 11 | } 12 | } 13 | } 14 | cout << "NO"; 15 | } -------------------------------------------------------------------------------- /208A - Dubstep/208A - Dubstep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a.size(); i++) { 7 | if (a[i] == 'W' && a[i + 1] == 'U' && a[i + 2] == 'B') { 8 | a.replace((size_t)i, 3, " "); 9 | i = -1; 10 | } 11 | } 12 | for (int i = 0; i < a.size(); i++) { 13 | if ((i == 0 && a[i] == ' ') || (i == a.size() - 1 && a[i] == ' ') || (a[i] == ' ' && a[i + 1] == ' ')) { 14 | a.erase((size_t)i, 1); 15 | } 16 | } 17 | cout << a; 18 | } -------------------------------------------------------------------------------- /214A - System of Equations/214A - System of Equations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, ans; 4 | int main() { 5 | cin >> n >> m; 6 | for (int i = 0; i <= max(n, m); i++) { 7 | for (int j = 0; j <= max(n, m); j++) { 8 | if ( ((i * i) + j) == n && ((j * j) + i) == m) { 9 | ans++; 10 | } 11 | } 12 | } 13 | cout << ans; 14 | } -------------------------------------------------------------------------------- /214B - Hometask/214B - Hometask.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int len, sum, mas[100005]; 5 | int main() { 6 | cin >> len; 7 | for (int i = 0; i < len; i++) { 8 | cin >> mas[i]; 9 | sum += mas[i]; 10 | } 11 | sort(mas, mas + len); 12 | reverse(mas, mas + len); 13 | if (mas[len - 1] != 0) { 14 | cout << "-1"; 15 | } else if (mas[0] == 0 || sum == 0) { 16 | cout << "0"; 17 | } else { 18 | if (sum % 3 == 0) { 19 | for (int i = 0; i < len; i++) { 20 | cout << mas[i]; 21 | } 22 | } else if (sum % 3 == 1) { 23 | for (int i = len - 1; i >= 0; i--) { 24 | if (mas[i] != 0 && mas[i] % 3 == 1) { 25 | sum -= mas[i]; 26 | mas[i] = -1; 27 | break; 28 | } 29 | } 30 | if (sum % 3 != 0) { 31 | int test = 0; 32 | for (int i = len - 1; i >= 0; i--) { 33 | if (mas[i] != 0 && mas[i] % 3 == 2) { 34 | mas[i] = -1; 35 | test++; 36 | } 37 | if (test == 2) { 38 | break; 39 | } 40 | } 41 | } 42 | if ((mas[0] == -1 || mas[1] == -1) && mas[2] == 0) { 43 | cout << 0; 44 | } else { 45 | for (int i = 0; i < len; i++) { 46 | if (mas[i] != -1) { 47 | cout << mas[i]; 48 | } 49 | } 50 | } 51 | } else if (sum % 3 == 2) { 52 | for (int i = len - 1; i >= 0; i--) { 53 | if (mas[i] != 0 && mas[i] % 3 == 2) { 54 | sum -= mas[i]; 55 | mas[i] = -1; 56 | break; 57 | } 58 | } 59 | if (sum % 3 != 0) { 60 | int test = 0; 61 | for (int i = len - 1; i >= 0; i--) { 62 | if (mas[i] != 0 && mas[i] % 3 == 1) { 63 | mas[i] = -1; 64 | test++; 65 | } 66 | if (test == 2) { 67 | break; 68 | } 69 | } 70 | } 71 | if ((mas[0] == -1 || mas[1] == -1) && mas[2] == 0) { 72 | cout << 0; 73 | } else { 74 | for (int i = 0; i < len; i++) { 75 | if (mas[i] != -1) { 76 | cout << mas[i]; 77 | } 78 | } 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /216A - Tiling with Hexagons/216A - Tiling with Hexagons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c; 4 | int main() { 5 | cin >> a >> b >> c; 6 | cout << ((c - 1) * (b - 1)) + (a * (b + c - 1)); 7 | } -------------------------------------------------------------------------------- /225A - Dice Tower/225A - Dice Tower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, x, y, z, u, h = 1; 4 | int main() { 5 | cin >> a >> b >> x >> y; 6 | b = 7 - b; 7 | for (int i = 1; i < a; i++) { 8 | cin >> z >> u; 9 | if (b == z || b == u || b == 7 - z || b == 7 - u) { 10 | cout << "NO"; 11 | break; 12 | } else h += 1; 13 | } 14 | if (h == a) { 15 | cout << "YES"; 16 | } 17 | } -------------------------------------------------------------------------------- /228A - Is your horseshoe on the other hoof/228A - Is your horseshoe on the other hoof.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int mas[5], e = 3; 5 | int main() { 6 | for (int i = 0; i < 4; i++) { 7 | cin >> mas[i]; 8 | } 9 | sort(mas, mas + 4); 10 | for (int i = 0; i < 3; i++) { 11 | if (mas[i] != mas[i + 1]) { 12 | e--; 13 | } 14 | } 15 | cout << e; 16 | } -------------------------------------------------------------------------------- /230A - Dragons/230A - Dragons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int s, n, a, b; 5 | vector > v; 6 | int main() { 7 | cin >> s >> n; 8 | for (int i = 0; i < n; i++) { 9 | cin >> a >> b; 10 | v.push_back(make_pair(a, b)); 11 | } 12 | sort(v.begin(), v.end()); 13 | for (int i = 0; i < n; i++) { 14 | if(s <= v[i].first){ 15 | cout << "NO"; 16 | return 0; 17 | } else { 18 | s += v[i].second; 19 | } 20 | } 21 | cout << "YES"; 22 | } -------------------------------------------------------------------------------- /231A - Team/231A - Team.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c, d, sum = 0; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b >> c >> d; 8 | if ((b + c + d) > 1) { 9 | sum++; 10 | } 11 | } 12 | cout << sum; 13 | 14 | } -------------------------------------------------------------------------------- /233A - Perfect Permutation/233A - Perfect Permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int mas[105], a; 4 | int main() { 5 | cin >> a; 6 | for (int i = 1; i <= a; i++) { 7 | mas[i] = i; 8 | } 9 | for (int j = 0; j <= a - 1; j += 2) { 10 | if (a % 2 == 0) { 11 | cout << mas[j + 2] << " " << mas[j + 1] << " "; 12 | } else { 13 | cout << -1; 14 | break; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /233B - Non-square Equation/233B - Non-square Equation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | __int64 cj(__int64 k) { 5 | __int64 a = 0; 6 | while (k > 0) { 7 | a += k % 10; 8 | k = k / 10; 9 | } 10 | return a; 11 | } 12 | __int64 n, i, g, j, xn = -1; 13 | double x1, x2; 14 | int main() { 15 | cin >> n; 16 | for (i = 1; i <= 81; i++) { 17 | x1 = (-i + sqrt(i * i + 4 * n)) / 2; 18 | x2 = (-i - sqrt(i * i + 4 * n)) / 2; 19 | g = (int) x1; 20 | j = (int) x2; 21 | if (g == x1 && j == x2) { 22 | if (g > j && g > 0 && cj(g) == i) { 23 | xn = (__int64)x1; 24 | break; 25 | } else if (j > g && j > 0 && cj(j) == i) { 26 | xn = (__int64)x2; 27 | break; 28 | } 29 | } 30 | } 31 | cout << xn; 32 | } -------------------------------------------------------------------------------- /236A - Boy or Girl/236A - Boy or Girl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | char ch; int i=0; 7 | sets1; 8 | while(cin>>ch) 9 | s1.insert(ch); 10 | if(s1.size()%2==0) 11 | cout<<"CHAT WITH HER!"; 12 | else 13 | cout<<"IGNORE HIM!"; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /237A - Free Cash/237A - Free Cash.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, h, m, arr[2460]; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> h >> m; 9 | arr[(h * 100) + m]++; 10 | } 11 | cout << endl << * max_element(arr, arr + 2460); 12 | } -------------------------------------------------------------------------------- /242B - Big Segment/242B - Big Segment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, mas1[100005], mas2[100005], x = 1000000000, y = 0, pas = -2; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> mas1[i] >> mas2[i]; 8 | } 9 | for (int i = 0; i < a; i++) { 10 | if (mas1[i] < x) { 11 | x = mas1[i]; 12 | } 13 | if (mas2[i] > y) { 14 | y = mas2[i]; 15 | } 16 | } 17 | for (int i = 0; i < a; i++) { 18 | if (mas1[i] == x && mas2[i] == y) { 19 | pas = i; 20 | break; 21 | } 22 | } 23 | cout << pas + 1 << endl; 24 | } -------------------------------------------------------------------------------- /246B - Increase and Decrease/246B - Increase and Decrease.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, pas = 0; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b; 8 | pas += b; 9 | } 10 | if (pas % a == 0) { 11 | cout << a; 12 | } else { 13 | cout << a - 1; 14 | } 15 | } -------------------------------------------------------------------------------- /248B - Chilly Willy/248B - Chilly Willy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b = 100, i; 4 | int main() { 5 | cin >> a; 6 | if (a == 1 || a == 2) { 7 | cout << "-1"; 8 | } else if (a == 3) { 9 | cout << "210"; 10 | } else { 11 | for (i = 0; i < a - 3; i++) { 12 | b = b * 10; 13 | b = b % 210; 14 | } 15 | b = 210 - b; 16 | if (b < 100) { 17 | cout << "1"; 18 | for (i = 0; i < a - 3; i++) { 19 | cout << "0"; 20 | } 21 | cout << b; 22 | } else { 23 | cout << "1"; 24 | for (i = 0; i < a - 4; i++) { 25 | cout << "0"; 26 | } 27 | cout << b; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /250A - Paper Work/250A - Paper Work.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, mas[105], pas = 0, c = 0, d = 0, g = 0; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> mas[i]; 8 | if (mas[i] < 0) { 9 | pas++; 10 | } 11 | } 12 | if (pas % 2 == 1) { 13 | pas++; 14 | } 15 | pas = pas / 2; 16 | if (pas == 0) { 17 | pas = 1; 18 | } 19 | cout << pas << endl; 20 | for (int i = 0; i < a; i++) { 21 | if (mas[i] < 0) { 22 | c++; 23 | } 24 | d++; 25 | if (c == 2 && pas > 1) { 26 | cout << d << " "; 27 | g += d; 28 | d = 0; 29 | c = 0; 30 | pas--; 31 | } else if (c == 2 && pas == 1) { 32 | break; 33 | } 34 | } 35 | cout << a - g; 36 | } -------------------------------------------------------------------------------- /255A - Greg's Workout/255A - Greg's Workout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, j = 1, a, b, c, d; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= n; i++) { 7 | cin >> d; 8 | if (j == 4) { 9 | j = 1; 10 | } 11 | if (j == 1) { 12 | a += d; 13 | } else if (j == 2) { 14 | b += d; 15 | } else if (j == 3) { 16 | c += d; 17 | } 18 | j++; 19 | } 20 | if (a > b && a > c) { 21 | cout << "chest"; 22 | } else if (b > a && b > c) { 23 | cout << "biceps"; 24 | } else { 25 | cout << "back"; 26 | } 27 | } -------------------------------------------------------------------------------- /25A - IQ test/25A - IQ test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, i = 0, j = 0, index = 0, indexEven, indexOdd; 4 | int main() { 5 | cin >> n; 6 | while ((i < 2 && j < 2) || (i != 1 && j != 1)) { 7 | cin >> m; 8 | index++; 9 | if (m % 2 == 0) { 10 | i++; 11 | indexEven = index; 12 | } else { 13 | j++; 14 | indexOdd = index; 15 | } 16 | } 17 | if (i < j) { 18 | cout << indexEven; 19 | } else { 20 | cout << indexOdd; 21 | } 22 | } -------------------------------------------------------------------------------- /263A - Beautiful Matrix/263A - Beautiful Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int b, sti, stj, pas; 5 | int main() { 6 | for (int i = 1; i < 6; i++) { 7 | for (int j = 1; j < 6; j++) { 8 | cin >> b; 9 | if (b == 1) { 10 | sti = i; 11 | stj = j; 12 | } 13 | } 14 | } 15 | pas = abs(sti - 3) + abs(stj - 3); 16 | cout << pas; 17 | } -------------------------------------------------------------------------------- /266A - Stones on the Table/266A - Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string b; 4 | int a, c; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a; i++) { 8 | if (b[i] == b[i + 1]) { 9 | c++; 10 | } 11 | } 12 | cout << c; 13 | } -------------------------------------------------------------------------------- /266B - Queue at the School/266B - Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, b; 5 | string a; 6 | int main() { 7 | cin >> n >> b >> a; 8 | for (int i = 0; i < b; i++) { 9 | for (int j = 0; j < n; j++) { 10 | if (a[j] == 'B' && a[j + 1] == 'G') { 11 | swap(a[j], a[j + 1]); 12 | j += 1; 13 | } 14 | } 15 | } 16 | cout << a; 17 | } -------------------------------------------------------------------------------- /268A - Games/268A - Games.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, mas1[31], mas2[31], pas = 0; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> mas1[i] >> mas2[i]; 8 | } 9 | for (int i = 0; i < a; i++) { 10 | for (int j = 0; j < a; j++) { 11 | if (mas1[i] == mas2[j]) { 12 | pas++; 13 | } 14 | } 15 | } 16 | cout << pas; 17 | } -------------------------------------------------------------------------------- /268B - Buttons/268B - Buttons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, v, pas = 0; 4 | int main() { 5 | cin >> a; 6 | pas += a; 7 | v = a - 1; 8 | for (int i = 2; i <= a; i++) { 9 | pas += (v - 1) * i + 1; 10 | v--; 11 | } 12 | cout << pas; 13 | } -------------------------------------------------------------------------------- /26B - Regular Bracket Sequence/26B - Regular Bracket Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int b, c; 5 | int main() { 6 | cin >> a; 7 | b = a.size(); 8 | for (int i = 0; i < a.size(); i++) { 9 | if (a[i] == '(') { 10 | c++; 11 | } else if (a[i] == ')') { 12 | c--; 13 | if (c < 0) { 14 | b--; 15 | c = 0; 16 | } 17 | } 18 | } 19 | cout << b - c; 20 | } -------------------------------------------------------------------------------- /270A - Fancy Fence/270A - Fancy Fence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | double a, b; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b; 8 | b = 360 / (180 - b); 9 | if (b == (int) b) { 10 | cout << "YES\n"; 11 | } else { 12 | cout << "NO\n"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /271A - Beautiful Year/271A - Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, i, mas[5], pas; 4 | int main() { 5 | cin >> a; 6 | a++; 7 | for (int k = a; k < 9100; k++) { 8 | b = a; 9 | while (b > 0) { 10 | mas[i] = b % 10; 11 | i++; 12 | b /= 10; 13 | } 14 | i = 0; 15 | for (int i = 0; i < 3; i++) { 16 | for (int j = i + 1; j < 4; j++) { 17 | if (mas[i] == mas[j]) { 18 | pas++; 19 | } 20 | } 21 | } 22 | if (pas == 0) { 23 | cout << a; 24 | return 0; 25 | } 26 | pas = 0; 27 | a++; 28 | } 29 | } -------------------------------------------------------------------------------- /271B - Prime Matrix/271B - Prime Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, mas[505][505], sac[100005], mina = 10000000, minb = 10000000, na = 0, nb = 0; 4 | int main() { 5 | cin >> a >> b; 6 | for (int i = 0; i < a; i++) { 7 | for (int j = 0; j < b; j++) { 8 | cin >> mas[i][j]; 9 | } 10 | } 11 | for (int i = 2; i < 100003; i++) { 12 | if (sac[i] == 0) { 13 | for (int j = 2 * i; j < 100003; j = j + i) { 14 | sac[j] = 1; 15 | } 16 | } 17 | } 18 | int k = 100003; 19 | for (int i = 100002; i >= 2; i--) { 20 | if (sac[i] == 0) k = i; 21 | else sac[i] = k - i; 22 | } 23 | sac[1] = 1; 24 | for (int i = 0; i < a; i++) { 25 | for (int j = 0; j < b; j++) { 26 | na += sac[mas[i][j]]; 27 | } 28 | if (mina > na) { 29 | mina = na; 30 | } 31 | na = 0; 32 | } 33 | for (int i = 0; i < b; i++) { 34 | for (int j = 0; j < a; j++) { 35 | nb += sac[mas[j][i]]; 36 | } 37 | if (minb > nb) { 38 | minb = nb; 39 | } 40 | nb = 0; 41 | } 42 | cout << min(mina, minb); 43 | } -------------------------------------------------------------------------------- /272B - Dima and Sequence/272B - Dima and Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long func(long long n) { 4 | long long a = 0; 5 | while (n > 0) { 6 | if (n % 2 == 1) a++; 7 | n = n / 2; 8 | } 9 | return a; 10 | } 11 | long long a, b, pas[40], ans; 12 | int main() { 13 | cin >> a; 14 | for (long long i = 0; i < a; i++) { 15 | cin >> b; 16 | pas[func(b)] += 1; 17 | } 18 | for (long long i = 0; i < 40; i++) { 19 | if (pas[i] != 0) { 20 | ans += pas[i] * (pas[i] - 1) / 2; 21 | } 22 | } 23 | cout << ans; 24 | } -------------------------------------------------------------------------------- /276A - Lunch Rush/276A - Lunch Rush.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | __int64 n, k, f, t, a = -1000000000; 4 | int main() { 5 | cin >> n >> k; 6 | while (n--) { 7 | cin >> f >> t; 8 | if (t <= k) { 9 | a = max(a, f); 10 | } else { 11 | a = max(a, f - (t - k)); 12 | } 13 | } 14 | cout << a; 15 | } 16 | -------------------------------------------------------------------------------- /281A - Word Capitalization/281A - Word Capitalization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int main() { 5 | cin >> a; 6 | if ((int) a[0] > 96) { 7 | a[0] -= 32; 8 | } 9 | cout << a; 10 | } -------------------------------------------------------------------------------- /282A - Bit++/282A - Bit++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string b; 4 | int a, c; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> b; 9 | if (b[0] == '+') { 10 | c++; 11 | } else if (b[0] == '-') { 12 | c--; 13 | } else if (b[0] == 'X' && b[1] == '-') { 14 | c--; 15 | } else if (b[0] == 'X' && b[1] == '+') { 16 | c++; 17 | } 18 | } 19 | cout << c; 20 | } -------------------------------------------------------------------------------- /287B - Pipeline/287B - Pipeline.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | unsigned long long a, c; 4 | long b, sum; 5 | int main() { 6 | cin >> a >> b; 7 | c = 1; 8 | while ((c < a) && (b > 1)) { 9 | c += b - 1; 10 | b--; 11 | sum++; 12 | } 13 | if (b == 1 && c < a) { 14 | cout << "-1"; 15 | } else { 16 | cout << sum; 17 | } 18 | } -------------------------------------------------------------------------------- /313A - Ilya and Bank Account/313A - Ilya and Bank Account.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | long long a, tenth, hundredth, pas; 5 | int main() { 6 | cin >> a; 7 | if (a > 0) { 8 | cout << a; 9 | } else { 10 | a = abs(a); 11 | tenth = a % 10; 12 | a /= 10; 13 | hundredth = a % 10; 14 | if (tenth < hundredth) { 15 | pas = (a / 10) * 10 + tenth; 16 | } else { 17 | pas = a; 18 | } 19 | cout << -pas; 20 | } 21 | } -------------------------------------------------------------------------------- /313B - Ilya and Queries/313B - Ilya and Queries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, k, arr[100001]; 4 | string a; 5 | int main() { 6 | cin >> a >> n; 7 | for (int i = 1; i < a.size(); i++) { 8 | arr[i + 1] = arr[i] + (a[i] == a[i - 1]); 9 | } 10 | for (int i = 1; i <= n; i++) { 11 | cin >> m >> k; 12 | cout << arr[k] - arr[m] << endl; 13 | } 14 | } -------------------------------------------------------------------------------- /318A - Even Odds/318A - Even Odds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long a, b, pas = 0; 4 | int main() { 5 | cin >> a >> b; 6 | if (a % 2 == 0) { 7 | if (b <= a / 2) { 8 | pas = b * 2 - 1; 9 | } else { 10 | pas = (b - (a / 2)) * 2; 11 | } 12 | } else { 13 | if (b <= a / 2 + 1) { 14 | pas = b * 2 - 1; 15 | } else { 16 | pas = (b - (a / 2 + 1)) * 2; 17 | } 18 | } 19 | cout << pas; 20 | } -------------------------------------------------------------------------------- /327A - Flipping Game/327A - Flipping Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, c, x, m, r = -1; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a; 8 | c += a; 9 | x += 1 - a * 2; 10 | r = max(r, x - m); 11 | m = min(x, m); 12 | } 13 | cout << r + c; 14 | } -------------------------------------------------------------------------------- /327B - Hungry Sequence/327B - Hungry Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a; 4 | int main() { 5 | cin >> a; 6 | for (int i = a + 1; i <= 2 * a; i++) { 7 | cout << i << " "; 8 | } 9 | } -------------------------------------------------------------------------------- /330A - Cakeminator/330A - Cakeminator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, arr[11][11], ind, ans; 4 | char c; 5 | int main() { 6 | cin >> n >> m; 7 | for (int i = 0; i < n; i++) { 8 | for (int j = 0; j < m; j++) { 9 | cin >> c; 10 | if (c == 'S') { 11 | arr[i][j] = 1; 12 | } 13 | } 14 | } 15 | for (int i = 0; i < n; i++) { 16 | ind = 0; 17 | for (int j = 0; j < m; j++) { 18 | if (arr[i][j] == 1) { 19 | ind = 1; 20 | break; 21 | } 22 | } 23 | if (ind == 0) { 24 | for (int j = 0; j < m; j++) { 25 | arr[i][j] = 2; 26 | } 27 | } 28 | } 29 | for (int i = 0; i < m; i++) { 30 | ind = 0; 31 | for (int j = 0; j < n; j++) { 32 | if (arr[j][i] == 1) { 33 | ind = 1; 34 | break; 35 | } 36 | } 37 | if (ind == 0) { 38 | for (int j = 0; j < n; j++) { 39 | arr[j][i] = 2; 40 | } 41 | } 42 | } 43 | for (int i = 0; i < n; i++) { 44 | for (int j = 0; j < m; j++) { 45 | if (arr[i][j] == 2) { 46 | ans++; 47 | } 48 | } 49 | } 50 | cout << ans; 51 | } -------------------------------------------------------------------------------- /336A - Vasily the Bear and Triangle/336A - Vasily the Bear and Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long a, b; 4 | int main() { 5 | cin >> a >> b; 6 | if (a > 0 && b > 0) { 7 | cout << 0 << " " << a + b << " " << a + b << " " << 0; 8 | } 9 | if (a < 0 && b > 0) { 10 | cout << -(-(a) + b) << " " << 0 << " " << 0 << " " << -(a) + b; 11 | } 12 | if (a > 0 && b < 0) { 13 | cout << 0 << " " << -(-(b) + a) << " " << a - (b) << " " << 0; 14 | } 15 | if (a < 0 && b < 0) { 16 | cout << -(-(a) - (b)) << " " << 0 << " " << 0 << " " << -(-(a) - (b)); 17 | } 18 | } -------------------------------------------------------------------------------- /337A - Puzzles/337A - Puzzles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, b, mas[55], minNum = 1001; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < b; i++) { 8 | cin >> mas[i]; 9 | } 10 | sort(mas, mas + b); 11 | for (int i = 0; i <= b - a; i++) { 12 | if (mas[i + a - 1] - mas[i] < minNum) { 13 | minNum = mas[i + a - 1] - mas[i]; 14 | } 15 | } 16 | cout << minNum; 17 | } -------------------------------------------------------------------------------- /339A - Helpful Maths/339A - Helpful Maths.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | string a; 5 | int mas[105], b; 6 | int main() { 7 | cin >> a; 8 | for (int i = 0; i < a.size(); i += 2) { 9 | mas[b] = a[i] - 48; 10 | b++; 11 | } 12 | sort(mas, mas + a.size() / 2 + 1); 13 | cout << mas[0]; 14 | for (int i = 1; i < a.size() / 2 + 1; i++) { 15 | cout << "+" << mas[i]; 16 | } 17 | } -------------------------------------------------------------------------------- /339B - Xenia and Ringroad/339B - Xenia and Ringroad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, a, cur = 1; 4 | __int64 pas = 0; 5 | int main() { 6 | cin >> n >> m; 7 | for (int i = 0; i < m; i++) { 8 | cin >> a; 9 | if (a >= cur) { 10 | pas += (a - cur); 11 | } else { 12 | pas += n - cur + a; 13 | } 14 | cur = a; 15 | } 16 | cout << pas; 17 | } -------------------------------------------------------------------------------- /344A - Magnets/344A - Magnets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, pas = 1; 4 | string b, c; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a - 1; i++) { 8 | cin >> c; 9 | if (b != c) { 10 | pas++; 11 | b = c; 12 | } 13 | } 14 | cout << pas; 15 | } -------------------------------------------------------------------------------- /347A - Difference Row/347A - Difference Row.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[105]; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> mas[i]; 9 | } 10 | sort(mas, mas + a); 11 | swap(mas[0], mas[a - 1]); 12 | for (int i = 0; i < a; i++) { 13 | cout << mas[i] << " "; 14 | } 15 | } -------------------------------------------------------------------------------- /349A - Cinema Line/349A - Cinema Line.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, k, numOfTF, numOfF; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> k; 8 | if (k == 25) { 9 | numOfTF++; 10 | } else if (k == 50) { 11 | if (numOfTF >= 1) { 12 | numOfTF--; 13 | numOfF++; 14 | } else { 15 | cout << "NO"; 16 | return 0; 17 | } 18 | } else if (k == 100) { 19 | if (numOfF >= 1 && numOfTF >= 1) { 20 | numOfF--; 21 | numOfTF--; 22 | } else if (numOfF == 0 && numOfTF >= 3) { 23 | numOfTF -= 3; 24 | } else { 25 | cout << "NO"; 26 | return 0; 27 | } 28 | } 29 | } 30 | cout << "YES"; 31 | } -------------------------------------------------------------------------------- /34A - Reconnaissance 2/34A - Reconnaissance 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[105], mas1[105], h, j; 5 | int main() { 6 | cin >> a; 7 | for (int i = 1; i <= a; i++) { 8 | cin >> mas[i]; 9 | } 10 | mas[a + 1] = mas[1]; 11 | for (int i = 1; i <= a; i++) { 12 | mas1[i] = abs(mas[i] - mas[i + 1]); 13 | } 14 | h = * min_element(mas1 + 1, mas1 + a + 1); 15 | for (int i = 1; i <= a; i++) { 16 | if (h == mas1[i]) { 17 | j = i; 18 | break; 19 | } 20 | } 21 | if (j != a) { 22 | cout << j << " " << j + 1; 23 | } else { 24 | cout << j << " " << 1; 25 | } 26 | } -------------------------------------------------------------------------------- /361B_Levko/361B_Levko.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,k; 6 | cin>>n>>k; 7 | int a[n+1]; 8 | if(n==1 && k==0) 9 | cout<<1; 10 | else if(k<=n-1) 11 | { 12 | a[1]=1; 13 | for (int i=2;i<=k+1;i++) 14 | a[i]=i ; 15 | for (int i=k+2;i<=n;i++) 16 | { 17 | a[i]=i; 18 | int temp=a[i]; 19 | a[i]=a[1]; 20 | a[1]=temp; 21 | } 22 | for (int i=1;i<=n;i++) 23 | cout< 2 | using namespace std; 3 | int mas[10005], a, b, c, d, e, pas = 0; 4 | int main() { 5 | cin >> a >> b; 6 | for (int i = 0; i < b; i++) { 7 | cin >> c >> d >> e; 8 | mas[c] -= e; 9 | mas[d] += e; 10 | } 11 | for (int i = 0; i <= a; i++) { 12 | if (mas[i] > 0) { 13 | pas += mas[i]; 14 | } 15 | } 16 | cout << pas; 17 | } -------------------------------------------------------------------------------- /379A - New Year Candles/379A - New Year Candles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, pas = 0; 4 | int main() { 5 | cin >> a >> b; 6 | pas = (a * b - 1) / (b - 1); 7 | cout << pas; 8 | } -------------------------------------------------------------------------------- /37A - Towers/37A - Towers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, l[1001], h = 1, u, he = 1; 5 | int main() { 6 | cin >> n; 7 | u = n; 8 | for (int i = 0; i < n; i++) { 9 | cin >> l[i]; 10 | } 11 | sort(l, l + n); 12 | for (int i = 1; i < n; i++) { 13 | if (l[i] == l[i - 1]) { 14 | h++; 15 | u--; 16 | } else { 17 | h = 1; 18 | } 19 | he = max(he, h); 20 | } 21 | cout << he << " " << u; 22 | } -------------------------------------------------------------------------------- /381A_SerejaAndDema/381A_SerejaAndDema.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i, j, sum1=0, sum2=0, k=1,x ; 6 | cin >> n; 7 | int a[n]; 8 | for(i=0;i>a[i] ; 10 | i=0 ; j=n-1 ; 11 | while(i<=j) 12 | { 13 | if(k%2!=0) 14 | { 15 | x=a[i]>a[j]?a[i++]:a[j--] ; 16 | sum1+=x; 17 | k++ ; 18 | } 19 | else 20 | { 21 | x=a[i]>a[j]?a[i++]:a[j--] ; 22 | sum2+=x; 23 | k++ ; 24 | } 25 | } 26 | cout< 2 | using namespace std; 3 | int n, ans; 4 | int main() { 5 | cin >> n; 6 | ans = n * n / 2; 7 | if (n % 2 != 0) { 8 | ans++; 9 | } 10 | cout << ans << endl; 11 | for (int i = 1; i <= n; i++) { 12 | for (int j = 1; j <= n; j++) { 13 | if (i % 2 != 0) { 14 | if (j % 2 != 0) { 15 | cout << 'C'; 16 | } else { 17 | cout << '.'; 18 | } 19 | } else { 20 | if (j % 2 == 0) { 21 | cout << 'C'; 22 | } else { 23 | cout << '.'; 24 | } 25 | } 26 | } 27 | cout << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /401A - Vanya and Cards/401A - Vanya and Cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, x, a, s, ans; 5 | int main() { 6 | cin >> n >> x; 7 | for (int i = 0; i < n; i++) { 8 | cin >> a; 9 | s += a; 10 | } 11 | s = abs(s); 12 | while (s > 0) { 13 | if (s - x >= 0) { 14 | s -= x; 15 | ans++; 16 | } else { 17 | x--; 18 | } 19 | } 20 | cout << ans; 21 | } -------------------------------------------------------------------------------- /405A - Gravity Flip/405A - Gravity Flip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[100]; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> mas[i]; 9 | } 10 | sort(mas, mas + a); 11 | for (int i = 0; i < a; i++) { 12 | cout << mas[i] << " "; 13 | } 14 | } -------------------------------------------------------------------------------- /41A - Translation/41A - Translation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a, b; 4 | int pas = 0; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] != b[a.size() - 1 - i]) { 9 | pas++; 10 | } 11 | } 12 | if (pas > 0) { 13 | cout << "NO"; 14 | } else { 15 | cout << "YES"; 16 | } 17 | } -------------------------------------------------------------------------------- /427A - Police Recruits/427A - Police Recruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | double a, b, pas, pas1 = 0; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> b; 8 | pas += b; 9 | if (pas < 0) { 10 | pas1++; 11 | pas = 0; 12 | } 13 | } 14 | cout << pas1; 15 | } -------------------------------------------------------------------------------- /431A - Black Square/431A - Black Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int arr[4], sum; 4 | string s; 5 | int main() { 6 | cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> s; 7 | for (int i = 0; i < s.size(); i++) { 8 | sum += arr[s[i] - 49]; 9 | } 10 | cout << sum; 11 | } -------------------------------------------------------------------------------- /432A - Choosing Teams/432A - Choosing Teams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, k, mas[2001], sum = 0; 5 | int main() { 6 | cin >> n >> k; 7 | for (int i = 1; i <= n; i++) { 8 | cin >> mas[i]; 9 | } 10 | sort(mas + 1, mas + n + 1); 11 | for (int i = 1; i <= n / 3; i++) { 12 | if (mas[i * 3] + k <= 5) { 13 | sum++; 14 | } 15 | } 16 | cout << sum; 17 | } -------------------------------------------------------------------------------- /439A - Devu the Singer and Churu the Joker/439A - Devu the Singer and Churu the Joker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, d, t, sum, pas; 4 | int main() { 5 | cin >> n >> d; 6 | for (int i = 0; i < n; i++) { 7 | cin >> t; 8 | sum += t; 9 | } 10 | sum += (n - 1) * 10; 11 | if (sum <= d) { 12 | pas = 2 * (n - 1) + (d - sum) / 5; 13 | cout << pas; 14 | } else { 15 | cout << -1; 16 | } 17 | } -------------------------------------------------------------------------------- /441A - Valera and Antique Items/441A - Valera and Antique Items.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, v, k, s, arr[51], m = 0, l = 0; 4 | int main() { 5 | cin >> n >> v; 6 | for (int i = 1; i <= n; i++) { 7 | cin >> k; 8 | l = 0; 9 | for (int j = 0; j < k; j++) { 10 | cin >> s; 11 | if (s < v && l == 0) { 12 | arr[m] = i; 13 | m++; 14 | l = 1; 15 | } 16 | } 17 | } 18 | cout << m << endl; 19 | for (int i = 0; i < m; i++) { 20 | cout << arr[i] << " "; 21 | } 22 | } -------------------------------------------------------------------------------- /443A - Anton and Letters/443A - Anton and Letters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string n; 4 | int ar[123], sum = 0; 5 | int main() { 6 | getline(cin, n); 7 | for (int i = 1; i < n.size(); i += 3) { 8 | ar[(int) n[i]] = 1; 9 | } 10 | for (int i = 0; i < 123; i++) { 11 | sum += ar[i]; 12 | } 13 | cout << sum; 14 | } -------------------------------------------------------------------------------- /448A - Rewards/448A - Rewards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a1, a2, a3, b1, b2, b3, n, as, bs, asd, bsd; 4 | int main() { 5 | cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n; 6 | as = a1 + a2 + a3; 7 | bs = b1 + b2 + b3; 8 | asd = as / 5; 9 | as -= asd * 5; 10 | bsd = bs / 10; 11 | bs -= bsd * 10; 12 | if (as > 0) { 13 | asd++; 14 | } 15 | if (bs > 0) { 16 | bsd++; 17 | } 18 | n -= (asd + bsd); 19 | if (n < 0) { 20 | cout << "NO"; 21 | } else { 22 | cout << "YES"; 23 | } 24 | } -------------------------------------------------------------------------------- /450A - Jzzhu and Children/450A - Jzzhu and Children.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | vector > v; 5 | int n, m, j = 0, k = 0, a, l; 6 | int main() { 7 | cin >> n >> m; 8 | for (int i = 0; i < n; i++) { 9 | cin >> a; 10 | v.push_back(make_pair(a, i)); 11 | } 12 | while (n + j > k) { 13 | if (v[k].first > m) { 14 | v.push_back(make_pair(v[k].first - m, v[k].second)); 15 | j++; 16 | } else { 17 | l = v[k].second + 1; 18 | } 19 | k++; 20 | } 21 | cout << l; 22 | } -------------------------------------------------------------------------------- /451A - Game With Sticks/451A - Game With Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, i; 4 | int main() { 5 | cin >> n >> m; 6 | if (n > m) { 7 | i = m; 8 | } else { 9 | i = n; 10 | } 11 | if (i % 2 == 0) { 12 | cout << "Malvika"; 13 | } else { 14 | cout << "Akshat"; 15 | } 16 | } -------------------------------------------------------------------------------- /451B - Sort the Array/451B - Sort the Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, s, sti = 1, eni = 1, m, ans; 4 | long long arr[100001]; 5 | int main() { 6 | cin >> n; 7 | for (int i = 1; i <= n; i++) { 8 | cin >> arr[i]; 9 | } 10 | for (int i = 1; i < n; i++) { 11 | if (arr[i + 1] < arr[i]) { 12 | if (m == 1) { 13 | cout << "no"; 14 | return 0; 15 | } else if (s == 0) { 16 | s++; 17 | sti = i; 18 | eni = i + 1; 19 | } else { 20 | eni = i + 1; 21 | } 22 | } else if (s != 0) { 23 | m = 1; 24 | } 25 | } 26 | if (s == 1) { 27 | if (sti != 1 && eni != n) { 28 | if ((arr[eni] >= arr[sti - 1] && arr[sti] <= arr[eni + 1])) { 29 | ans = 1; 30 | } 31 | } else if (sti == 1 && eni != n && eni != 0) { 32 | if (arr[sti] <= arr[eni + 1]) { 33 | ans = 1; 34 | } 35 | } else if (sti != 1 && eni == n) { 36 | if (arr[eni] >= arr[sti - 1]) { 37 | ans = 1; 38 | } 39 | } else { 40 | ans = 1; 41 | } 42 | } else { 43 | ans = 1; 44 | } 45 | if (ans == 1) { 46 | cout << "yes" << endl << min(sti, eni) << " " << max(sti, eni); 47 | } else { 48 | cout << "no"; 49 | } 50 | } -------------------------------------------------------------------------------- /452A - Eevee/452A - Eevee.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | string a[8] = { 5 | "vaporeon", 6 | "jolteon", 7 | "flareon", 8 | "espeon", 9 | "umbreon", 10 | "leafeon", 11 | "glaceon", 12 | "sylveon" 13 | }; 14 | string c; 15 | int mas[8], b = 0, max1 = 0, ert = 0; 16 | int main() { 17 | cin >> b >> c; 18 | for (int i = 0; i < b; i++) { 19 | if (c[i] != '.') { 20 | ert++; 21 | } 22 | } 23 | for (int i = 0; i < c.size(); i++) { 24 | for (int j = 0; j < 8; j++) { 25 | if (c[i] != '.' && c[i] == a[j][i]) { 26 | mas[j]++; 27 | } 28 | } 29 | } 30 | for (int i = 0; i < 8; i++) { 31 | if (mas[i] == * max_element(mas, mas + b + 1)) { 32 | max1 = i; 33 | } 34 | } 35 | if (max1 == 7 && ert == 0 && b == 6) { 36 | cout << "espeon"; 37 | } else if (max1 == 7 && ert == 0 && b == 8) { 38 | cout << "vaporeon"; 39 | } else { 40 | cout << a[max1]; 41 | } 42 | } -------------------------------------------------------------------------------- /454A - Little Pony and Crystal Mine/454A - Little Pony and Crystal Mine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= (n / 2) + 1; i++) { 7 | for (int j = 1; j <= n; j++) { 8 | if (j > (n / 2) + 1 - i && j < (n / 2) + 1 + i) { 9 | cout << 'D'; 10 | } else { 11 | cout << "*"; 12 | } 13 | } 14 | cout << endl; 15 | } 16 | for (int i = (n / 2); i > 0; i--) { 17 | for (int j = 1; j <= n; j++) { 18 | if (j > (n / 2) + 1 - i && j < (n / 2) + 1 + i) { 19 | cout << 'D'; 20 | } else { 21 | cout << "*"; 22 | } 23 | } 24 | cout << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /456A - Laptops/456A - Laptops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, b; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a >> b; 8 | if (a != b) { 9 | cout << "Happy Alex"; 10 | return 0; 11 | } 12 | } 13 | cout << "Poor Alex"; 14 | } -------------------------------------------------------------------------------- /459A - Pashmak and Garden/459A - Pashmak and Garden.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int x1, y1, x2, y2, x3, y3, x4, y4, a; 5 | int main() { 6 | cin >> x1 >> y1 >> x2 >> y2; 7 | if (x1 == x2) { 8 | a = y2 - y1; 9 | x3 = x1 + a; 10 | y3 = y1; 11 | x4 = x2 + a; 12 | y4 = y3 + a; 13 | } else if (y1 == y2) { 14 | a = x2 - x1; 15 | x3 = x1; 16 | y3 = y1 + a; 17 | x4 = x3 + a; 18 | y4 = y2 + a; 19 | } else { 20 | if (abs(x2 - x1) == abs(y2 - y1)) { 21 | x3 = x1; 22 | y3 = y2; 23 | x4 = x2; 24 | y4 = y1; 25 | } else { 26 | cout << -1; 27 | return 0; 28 | } 29 | } 30 | cout << x3 << " " << y3 << " " << x4 << " " << y4; 31 | } 32 | -------------------------------------------------------------------------------- /459B - Pashmak and Flowers/459B - Pashmak and Flowers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | __int64 a, arr[2000001], numOfMinElements = 1, numOfMaxElements = 1, dif, num = 1; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> arr[i]; 9 | } 10 | sort(arr, arr + a); 11 | if (arr[0] != arr[a - 1]) { 12 | for (__int64 i = 1; i < a; i++) { 13 | if (arr[i] == arr[i - 1]) { 14 | numOfMinElements++; 15 | } else { 16 | break; 17 | } 18 | } 19 | for (__int64 i = a - 2; i > -1; i--) { 20 | if (arr[i] == arr[i + 1]) { 21 | numOfMaxElements++; 22 | } else { 23 | break; 24 | } 25 | } 26 | num = numOfMinElements * numOfMaxElements; 27 | } else { 28 | num = (a * (a - 1)) / 2; 29 | } 30 | dif = arr[a - 1] - arr[0]; 31 | cout << dif << " " << num; 32 | } -------------------------------------------------------------------------------- /460A - Vasya and Socks/460A - Vasya and Socks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n; 4 | int main() { 5 | cin >> n; 6 | if (n % 2 == 0) { 7 | cout << n - 4 << " 4"; 8 | } else { 9 | cout << n - 9 << " 9"; 10 | } 11 | } -------------------------------------------------------------------------------- /461A - Appleman and Toastman/461A - Appleman and Toastman.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | __int64 n, arr[300001], sum, suma, sumb; 5 | int main() { 6 | cin >> n; 7 | for (int i = 0; i < n; i++) { 8 | cin >> arr[i]; 9 | sum += arr[i]; 10 | } 11 | sort(arr, arr + n); 12 | suma = sum; 13 | if (n != 1) { 14 | sum *= 2; 15 | } 16 | for (int i = 0; i < n - 2; i++) { 17 | sumb = suma - arr[i]; 18 | sum += sumb; 19 | suma -= arr[i]; 20 | } 21 | cout << sum; 22 | } -------------------------------------------------------------------------------- /466A - Cheap Travel/466A - Cheap Travel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, ans; 4 | double a, b; 5 | int main() { 6 | cin >> n >> m >> a >> b; 7 | if (a * n > (b / m) * n) { 8 | if (n % m == 0) { 9 | ans = (int) (n / m * b); 10 | } else if (n < m) { 11 | ans = (int) min(a * n, b); 12 | } else { 13 | if (a < b) { 14 | ans = (int) ((n / m * b) + (n % m * a)); 15 | } else { 16 | ans = (int) ((n / m * b) + b); 17 | } 18 | } 19 | } else { 20 | ans = (int) (n * a); 21 | } 22 | cout << ans; 23 | } -------------------------------------------------------------------------------- /467A - George and Accommodation/467A - George and Accommodation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, p, q, pas = 0; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> p >> q; 8 | if (q - p >= 2) { 9 | pas++; 10 | } 11 | } 12 | cout << pas; 13 | } -------------------------------------------------------------------------------- /469A - I Wanna Be the Guy/469A - I Wanna Be the Guy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, p, q, a, b, d[100]; 5 | int main() { 6 | cin >> n >> p; 7 | for (int i = 0; i < p; i++) { 8 | cin >> a; 9 | d[a - 1] = 1; 10 | } 11 | cin >> q; 12 | for (int i = 0; i < q; i++) { 13 | cin >> b; 14 | d[b - 1] = 1; 15 | } 16 | if ( * min_element(d, d + n) == 1) { 17 | cout << "I become the guy."; 18 | } else { 19 | cout << "Oh, my keyboard!"; 20 | } 21 | } -------------------------------------------------------------------------------- /471A - MUH and Sticks/471A - MUH and Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int arr[6], arr2[10]; 5 | int main() { 6 | for (int i = 0; i < 6; i++) { 7 | cin >> arr[i]; 8 | } 9 | sort(arr, arr + 6); 10 | for (int i = 0; i < 6; i++) { 11 | arr2[arr[i]]++; 12 | } 13 | sort(arr2, arr2 + 10); 14 | reverse(arr2, arr2 + 10); 15 | if (arr2[0] == 6) { 16 | cout << "Elephant"; 17 | } else if (arr2[0] == 5) { 18 | cout << "Bear"; 19 | } else if (arr2[0] == 4) { 20 | if (arr2[1] == 2) { 21 | cout << "Elephant"; 22 | } else { 23 | cout << "Bear"; 24 | } 25 | } else { 26 | cout << "Alien"; 27 | } 28 | } -------------------------------------------------------------------------------- /472A - Design Tutorial Learn from Math/472A - Design Tutorial Learn from Math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n; 4 | int main() { 5 | cin >> n; 6 | if (n % 2 == 0) { 7 | cout << n - 4 << " 4"; 8 | } else { 9 | cout << n - 9 << " 9"; 10 | } 11 | } -------------------------------------------------------------------------------- /474A - Keyboard/474A - Keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a, b, c = "qwertyuiopasdfghjkl;zxcvbnm,./"; 4 | int ite = 0; 5 | int main() { 6 | cin >> a >> b; 7 | if (a == "R") { 8 | ite = -1; 9 | } else if (a == "L") { 10 | ite = 1; 11 | } 12 | for (int i = 0; i < b.size(); i++) { 13 | for (int j = 0; j < 30; j++) { 14 | if (c[j] == b[i]) { 15 | b[i] = c[j + ite]; 16 | break; 17 | } 18 | } 19 | } 20 | cout << b; 21 | } -------------------------------------------------------------------------------- /476A - Dreamoon and Stairs/476A - Dreamoon and Stairs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m; 4 | int main() { 5 | cin >> n >> m; 6 | if (n < m) { 7 | cout << -1; 8 | return 0; 9 | } else { 10 | cout << (n + (2 * m) - 1) / 2 / m * m; 11 | } 12 | } -------------------------------------------------------------------------------- /478A - Initial Bet/478A - Initial Bet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c, d, e, sum; 4 | int main() { 5 | cin >> a >> b >> c >> d >> e; 6 | sum = a + b + c + d + e; 7 | if (sum % 5 == 0 && sum > 0){ 8 | cout << sum / 5; 9 | } else { 10 | cout << -1; 11 | } 12 | } -------------------------------------------------------------------------------- /479A - Expression/479A - Expression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c; 4 | int main() { 5 | cin >> a >> b >> c; 6 | cout << max(max((a + b + c), (a * (b + c))), max(((a + b) * c), (a * b * c))); 7 | } -------------------------------------------------------------------------------- /486A - Calculating Function/486A - Calculating Function.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long i; 4 | int main() { 5 | cin >> i; 6 | if (i % 2 == 0) { 7 | cout << i / 2; 8 | } else { 9 | cout << -((i / 2) + 1); 10 | } 11 | } -------------------------------------------------------------------------------- /489C - Given Length and Sum of Digits/489C - Given Length and Sum of Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, e; 4 | string ma, mi; 5 | int main() { 6 | cin >> a >> b; 7 | if (b == 0) { 8 | if (a == 1) { 9 | cout << "0 0"; 10 | } else { 11 | cout << "-1 -1"; 12 | } 13 | return 0; 14 | } 15 | for (int i = 0; i < a; i++) { 16 | e = min(b, 9); 17 | ma += (char)(e + 48); 18 | b -= e; 19 | } 20 | if (b > 0) { 21 | cout << "-1 -1"; 22 | return 0; 23 | } 24 | for (int i = a - 1; i >= 0; i--) { 25 | mi += ma[i]; 26 | } 27 | for (int i = 0; i < mi.size(); i++) { 28 | if (mi[i] != '0') { 29 | mi[i]--; 30 | mi[0]++; 31 | break; 32 | } 33 | } 34 | cout << mi << " " << ma; 35 | } -------------------------------------------------------------------------------- /490A - Team Olympiad/490A - Team Olympiad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, mas[4][5001], ma[4], ans; 4 | int main() { 5 | cin >> a; 6 | for (int i = 1; i <= a; i++) { 7 | cin >> b; 8 | mas[b][ma[b]++] = i; 9 | } 10 | ans = min(ma[1], min(ma[2], ma[3])); 11 | cout << ans << endl; 12 | for (int i = 0; i < ans; i++) { 13 | cout << mas[1][i] << " " << mas[2][i] << " " << mas[3][i] << endl; 14 | } 15 | } -------------------------------------------------------------------------------- /492A - Vanya and Cubes/492A - Vanya and Cubes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, i = 0, last = 0, current = 0; 4 | int main() { 5 | cin >> a; 6 | while (a > 0) { 7 | i++; 8 | current = last + i; 9 | last = current; 10 | a -= current; 11 | if (a < 0) { 12 | i--; 13 | } 14 | } 15 | cout << i; 16 | } -------------------------------------------------------------------------------- /499B - Lecture/499B - Lecture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n, m , i ,j ; 7 | cin >>n>>m ; 8 | string l1[m+1], l2[m+1], text[n+1], ans[n+1] ; 9 | for(i=1;i<=m; i++) 10 | cin>>l1[i]>>l2[i]; 11 | for(i=1;i<=n;i++) 12 | cin>>text[i] ; 13 | for(i=1;i<=n;i++) 14 | { 15 | for(j=1;j<=m;j++) 16 | { 17 | if(text[i]==l1[j]) 18 | { 19 | ans[i] = l1[j].length()<=l2[j].length()?l1[j]:l2[j] ; 20 | } 21 | } 22 | } 23 | for(i=1;i<=n;i++) 24 | cout< 2 | using namespace std; 3 | int a; 4 | int main() { 5 | cin >> a; 6 | if (a % 2 == 0 && a != 2) { 7 | cout << "YES"; 8 | } else { 9 | cout << "NO"; 10 | } 11 | } -------------------------------------------------------------------------------- /501A - Contest/501A - Contest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c, d, v, m; 4 | int main() { 5 | cin >> a >> b >> c >> d; 6 | m = max(3 * a / 10, a - a / 250 * c); 7 | v = max(3 * b / 10, b - b / 250 * d); 8 | if (m > v) { 9 | cout << "Misha"; 10 | } else if (v > m) { 11 | cout << "Vasya"; 12 | } else { 13 | cout << "Tie"; 14 | } 15 | } -------------------------------------------------------------------------------- /507A - Amr and Music/507A - Amr and Music.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int n, k, sum, num, b, c[101]; 6 | vector < pair> a; 7 | int main() { 8 | cin >> n >> k; 9 | for (int i = 1; i <= n; i++) { 10 | cin >> b; 11 | a.push_back( make_pair(b, i)); 12 | } 13 | sort(a.begin(), a.end()); 14 | for (int i = 0; i < n; i++) { 15 | sum += a[i].first; 16 | if (sum <= k) { 17 | num++; 18 | c[i] = a[i].second; 19 | } else { 20 | break; 21 | } 22 | } 23 | cout << num << endl; 24 | for (int i = 0; i < num; i++) { 25 | cout << c[i] << " "; 26 | } 27 | } -------------------------------------------------------------------------------- /509A - Maximum in Table/509A - Maximum in Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, arr[10][10]; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | for (int j = 0; j < a; j++) { 8 | if (i == 0) { 9 | arr[i][j] = 1; 10 | } else if (j == 0) { 11 | arr[i][j] = 1; 12 | } else { 13 | arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; 14 | } 15 | } 16 | } 17 | cout << arr[a - 1][a - 1]; 18 | } -------------------------------------------------------------------------------- /50A - Domino piling/50A - Domino piling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int m, n, a; 4 | int main() { 5 | cin >> m >> n; 6 | if ((m * n) % 2 == 0) { 7 | a = (m * n) / 2; 8 | } else { 9 | a = ((m * n) - 1) / 2; 10 | } 11 | cout << a; 12 | } -------------------------------------------------------------------------------- /510A - Fox And Snake/510A - Fox And Snake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m; 4 | int main() { 5 | cin >> n >> m; 6 | for (int i = 1; i <= n; i++) { 7 | for (int j = 1; j <= m; j++) { 8 | if (i % 2 == 1) { 9 | cout << "#"; 10 | } else { 11 | if ((i / 2) % 2 == 1) { 12 | if (j != m) { 13 | cout << "."; 14 | } else { 15 | cout << "#"; 16 | } 17 | } else { 18 | if (j != 1) { 19 | cout << "."; 20 | } else { 21 | cout << "#"; 22 | } 23 | } 24 | } 25 | } 26 | cout << endl; 27 | } 28 | } -------------------------------------------------------------------------------- /510C - Fox And Names/510C - Fox And Names.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | enum{ 9 | white=0, 10 | grey, 11 | black 12 | }color; 13 | 14 | int first(int mat[26][26],int v){ 15 | for(int i = 0;i<26;i++)if(mat[v][i]==1) return i; 16 | return 26; 17 | } 18 | 19 | int next(int mat[26][26],int v,int w){ 20 | for(int i = w+1;i<26;i++)if(mat[v][i]==1) return i; 21 | return 26; 22 | } 23 | 24 | void TPSort(int mat[26][26],int* visit,int v,int* valido,stack &s){ 25 | visit[v] = grey; 26 | int w = first(mat,v); 27 | while(w<26){ 28 | if(visit[w]==white){ 29 | TPSort(mat,visit,w,valido,s); 30 | } 31 | w = next(mat,v,w); 32 | } 33 | if(valido[v]==1) s.push(v); 34 | } 35 | 36 | void fullvisitTPS(int mat[26][26],int* visit,int* valido,stack &s){ 37 | for(int i = 0;i<26;i++){ 38 | if(visit[i]==0&&valido[i]==1){ 39 | TPSort(mat,visit,i,valido,s); 40 | } 41 | } 42 | } 43 | 44 | void DFS(int mat[26][26],int* visit,int v,int* valido,stack &s){ 45 | visit[v] = grey; 46 | int w = first(mat,v); 47 | while(w<26){ 48 | if(visit[w]==white){ 49 | DFS(mat,visit,w,valido,s); 50 | } 51 | else if(visit[w]==grey){ 52 | 53 | printf("Impossible\n"); 54 | exit(0); 55 | } 56 | w = next(mat,v,w); 57 | } 58 | visit[v] = black; 59 | } 60 | 61 | void fullvisitDFS(int mat[26][26],int* visit,int* valido,stack &s){ 62 | for(int i = 0;i<26;i++){ 63 | if(visit[i]==0&&valido[i]==1){ 64 | DFS(mat,visit,i,valido,s); 65 | } 66 | } 67 | } 68 | 69 | 70 | int main() 71 | { 72 | int newOrder[26][26]={0}; 73 | int newOrderVisit[26]={0}; 74 | int qtd; 75 | int visit[26] = {0}; 76 | stack s; 77 | char aux[200]; 78 | char input[200]; 79 | scanf("%d",&qtd); 80 | scanf("%s",aux); 81 | qtd--; 82 | while(qtd--){ 83 | scanf("%s",input); 84 | int k=-1; 85 | for(int i = 0;input[i]!='\0'&&aux[i]!='\0';i++){ 86 | if(input[i]!=aux[i]){ 87 | k = i; 88 | break; 89 | } 90 | } 91 | if(k>-1){ 92 | newOrder[aux[k]-'a'][input[k]-'a'] = 1; 93 | newOrderVisit[aux[k]-'a'] = 1; 94 | newOrderVisit[input[k]-'a'] = 1; 95 | } 96 | if(strlen(aux)>strlen(input)&&k==-1){ 97 | printf("Impossible\n"); 98 | return 0; 99 | } 100 | strcpy(aux,input); 101 | } 102 | fullvisitDFS(newOrder,visit,newOrderVisit,s); 103 | 104 | for(int i = 0;i<26;i++)visit[i] = 0; 105 | 106 | fullvisitTPS(newOrder,visit,newOrderVisit,s); 107 | 108 | for(int i = 0;i<26;i++){ 109 | if(newOrderVisit[i] == 0)printf("%c",i+'a'); 110 | else{ 111 | while(!s.empty()&&s.top()<=(i)){ 112 | char help = s.top()+'a'; 113 | printf("%c",help); 114 | s.pop(); 115 | } 116 | } 117 | } 118 | 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /513A - Game/513A - Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n1, n2, k1, k2; 4 | int main() { 5 | cin >> n1 >> n2 >> k1 >> k2; 6 | if (n2 >= n1) { 7 | cout << "Second"; 8 | } else { 9 | cout << "First"; 10 | } 11 | } -------------------------------------------------------------------------------- /514A - Chewbaсca and Number/514A - Chewbaсca and Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | char invert(char c, int isFirst) { 4 | int d = c - 48; 5 | char e; 6 | if (isFirst == 1 && d == 9) { 7 | e = c; 8 | } else { 9 | if (9 - d < d) { 10 | e = (char) (9 - d + 48); 11 | } else { 12 | e = c; 13 | } 14 | } 15 | return e; 16 | } 17 | string a; 18 | int main() { 19 | cin >> a; 20 | for (int i = 0; i < a.size(); i++) { 21 | if (i == 0) { 22 | a[i] = invert(a[i], 1); 23 | } else { 24 | a[i] = invert(a[i], 0); 25 | } 26 | } 27 | cout << a; 28 | } -------------------------------------------------------------------------------- /515A - Drazil and Date/515A - Drazil and Date.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, b, c; 5 | int main() { 6 | cin >> a >> b >> c; 7 | if (c >= abs(a) + abs(b) && (c - (abs(a) + abs(b))) % 2 == 0) { 8 | cout << "Yes"; 9 | } else { 10 | cout << "No"; 11 | } 12 | } -------------------------------------------------------------------------------- /515C - Drazil and Factorial/515C - Drazil and Factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, num; 5 | string a, b, c = "322", d = "7222", e = "53", f = "7332"; 6 | int main() { 7 | cin >> n >> a; 8 | for (int i = 0; i < n; i++) { 9 | num = a[i] - 48; 10 | if (num > 1) { 11 | if (num == 4) { 12 | b += c; 13 | } else if (num == 8) { 14 | b += d; 15 | } else if (num == 6) { 16 | b += e; 17 | } else if (num == 9) { 18 | b += f; 19 | } else { 20 | b += a[i]; 21 | } 22 | } 23 | } 24 | sort(b.begin(), b.end()); 25 | reverse(b.begin(), b.end()); 26 | cout << b; 27 | } -------------------------------------------------------------------------------- /519A - A and B and Chess/519A - A and B and Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | string a; 5 | int whi, blk; 6 | int main() { 7 | for (int i = 0; i < 8; i++) { 8 | cin >> a; 9 | for (int j = 0; j < 8; j++) { 10 | if (a[j] == 'Q') { 11 | whi += 9; 12 | } else if (a[j] == 'R') { 13 | whi += 5; 14 | } else if (a[j] == 'B') { 15 | whi += 3; 16 | } else if (a[j] == 'N') { 17 | whi += 3; 18 | } else if (a[j] == 'P') { 19 | whi += 1; 20 | } else if (a[j] == 'q') { 21 | blk += 9; 22 | } else if (a[j] == 'r') { 23 | blk += 5; 24 | } else if (a[j] == 'b') { 25 | blk += 3; 26 | } else if (a[j] == 'n') { 27 | blk += 3; 28 | } else if (a[j] == 'p') { 29 | blk += 1; 30 | } 31 | } 32 | } 33 | if (whi > blk) { 34 | cout << "White"; 35 | } else if (blk > whi) { 36 | cout << "Black"; 37 | } else { 38 | cout << "Draw"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /519B - A and B and Compilation Errors/519B - A and B and Compilation Errors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n; 4 | __int64 a, b, c, suma, sumb, sumc; 5 | int main() { 6 | cin >> n; 7 | for (int i = 0; i < n; i++) { 8 | cin >> a; 9 | suma += a; 10 | } 11 | for (int i = 0; i < n - 1; i++) { 12 | cin >> b; 13 | sumb += b; 14 | } 15 | cout << suma - sumb << endl; 16 | for (int i = 0; i < n - 2; i++) { 17 | cin >> c; 18 | sumc += c; 19 | } 20 | cout << sumb - sumc; 21 | } -------------------------------------------------------------------------------- /519C - A and B and Team Training/519C - A and B and Team Training.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | typedef long long ll; 5 | vector v; 6 | 7 | int main() { 8 | int ans = 0; 9 | int n, m; 10 | cin >> n >> m; 11 | while (n && m) { 12 | if (n > m) { 13 | if (n >= 2) { 14 | n -= 2; 15 | --m; 16 | ++ans; 17 | } else { 18 | break; 19 | } 20 | } else { 21 | if (m >= 2) { 22 | m -= 2; 23 | --n; 24 | ++ans; 25 | } else { 26 | break; 27 | } 28 | } 29 | } 30 | cout << ans; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /520A - Pangram/520A - Pangram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, mas[26]; 5 | string b; 6 | int main() { 7 | cin >> a >> b; 8 | for (int i = 0; i < a; i++) { 9 | if (b[i] > 96) { 10 | mas[(int) b[i] - 97] = 1; 11 | } else { 12 | mas[(int) b[i] - 65] = 1; 13 | } 14 | } 15 | if(* min_element(mas, mas + 26) == 0) { 16 | cout << "NO"; 17 | } else { 18 | cout << "YES"; 19 | } 20 | } -------------------------------------------------------------------------------- /527A - Playing with Paper/527A - Playing with Paper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | __int64 a, b, ans, di; 4 | int main() { 5 | cin >> a >> b; 6 | while (a > 0 && b > 0) { 7 | if (a > b) { 8 | di = a/b; 9 | ans += di; 10 | a -= di * b; 11 | } else if (b > a) { 12 | di = b/a; 13 | ans += di; 14 | b -= di * a; 15 | } else { 16 | ans++; 17 | a = 0; 18 | b = 0; 19 | } 20 | } 21 | cout << ans; 22 | } -------------------------------------------------------------------------------- /535A - Tavas and Nafas/535A - Tavas and Nafas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c; 4 | string arr[28] = { 5 | "zero", 6 | "one", 7 | "two", 8 | "three", 9 | "four", 10 | "five", 11 | "six", 12 | "seven", 13 | "eight", 14 | "nine", 15 | "ten", 16 | "eleven", 17 | "twelve", 18 | "thirteen", 19 | "fourteen", 20 | "fifteen", 21 | "sixteen", 22 | "seventeen", 23 | "eighteen", 24 | "nineteen", 25 | "twenty", 26 | "thirty", 27 | "forty", 28 | "fifty", 29 | "sixty", 30 | "seventy", 31 | "eighty", 32 | "ninety" 33 | }; 34 | int main() { 35 | cin >> a; 36 | if (a < 21) { 37 | cout << arr[a]; 38 | } else { 39 | if (a % 10 == 0) { 40 | b = a / 10; 41 | cout << arr[18 + b]; 42 | } else { 43 | b = a / 10; 44 | c = a % 10; 45 | cout << arr[18 + b] << "-" << arr[c]; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /540A - Combination Lock/540A - Combination Lock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, numb, numc, pas = 0; 5 | string b, c; 6 | int main() { 7 | cin >> a >> b >> c; 8 | for (int i = 0; i < a; i++) { 9 | numb = (int) b[i] - 48; 10 | numc = (int) c[i] - 48; 11 | if (numb > numc) { 12 | numb = numc + numb; 13 | numc = numb - numc; 14 | numb -= numc; 15 | } 16 | if (abs(numb - numc) < (numb + (9 - numc) + 1)) { 17 | pas += abs(numb - numc); 18 | } else { 19 | pas += numb + (9 - numc) + 1; 20 | } 21 | } 22 | cout << pas; 23 | } -------------------------------------------------------------------------------- /545A - Toy Cars/545A - Toy Cars.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, arr[101], sum, b; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= n; i++) { 7 | b = 0; 8 | for (int j = 1; j <= n; j++) { 9 | cin >> a; 10 | if(b == 0) { 11 | if (a == -1) { 12 | b = 1; 13 | } else if (a == 1) { 14 | arr[i] = 1; 15 | } else if (a == 2) { 16 | arr[j] = 1; 17 | } else if (a == 3) { 18 | arr[i] = 1; 19 | arr[j] = 1; 20 | } 21 | } 22 | } 23 | } 24 | for (int i = 1; i <= n; i++) { 25 | if (arr[i] == 0) { 26 | sum++; 27 | } 28 | } 29 | cout << sum << endl; 30 | for (int i = 1; i <= n; i++) { 31 | if (arr[i] == 0) { 32 | cout << i << " "; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /546A - Soldier and Bananas/546A - Soldier and Bananas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int k, n, w, pas = 0; 4 | int main() { 5 | cin >> k >> n >> w; 6 | for (int i = 1; i <= w; i++) { 7 | pas += k * i; 8 | } 9 | if (pas - n < 0) { 10 | cout << 0; 11 | } else { 12 | cout << pas - n; 13 | } 14 | } -------------------------------------------------------------------------------- /551A - GukiZ and Contest/551A - GukiZ and Contest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, arr[2001], pos = 1; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> arr[i]; 8 | } 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 0; j < n; j++) { 11 | if (arr[i] < arr[j]) { 12 | pos++; 13 | } 14 | } 15 | cout << pos << " "; 16 | pos = 1; 17 | } 18 | } -------------------------------------------------------------------------------- /552B - Vanya and Books/552B - Vanya and Books.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | __int64 a, x, ans, num; 5 | int l; 6 | int main() { 7 | cin >> a; 8 | x = a; 9 | while (x != 0) { 10 | x /= 10; 11 | l++; 12 | } 13 | for (int i = l; i > 0; i--) { 14 | if (i == l) { 15 | ans += (a - round(pow(10, i - 1)) + 1) * i; 16 | } else { 17 | num = round(pow(10, i)); 18 | ans += (num - (num / 10)) * i; 19 | } 20 | } 21 | cout << ans; 22 | } -------------------------------------------------------------------------------- /556A - Case of the Zeros and Ones/556A - Case of the Zeros and Ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, ones, zeros, m; 4 | string b; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a; i++) { 8 | if (b[i] == '1') { 9 | ones++; 10 | } else { 11 | zeros++; 12 | } 13 | } 14 | m = min(ones, zeros); 15 | cout << a - (m * 2); 16 | } -------------------------------------------------------------------------------- /567A - Lineland Mail/567A - Lineland Mail.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, arr[1000001]; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> arr[i]; 8 | } 9 | for (int i = 0; i < n; i++) { 10 | if (i == 0) { 11 | cout << arr[1] - arr[0] << " " << arr[n - 1] - arr[0] << endl; 12 | } else if (i == n - 1) { 13 | cout << arr[n - 1] - arr[n - 2] << " " << arr[n - 1] - arr[0] << endl; 14 | } else { 15 | cout << min(arr[i + 1] - arr[i], arr[i] - arr[i - 1]) << " " << max(arr[i] - arr[0], arr[n - 1] - arr[i]) << endl; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /570A - Elections/570A - Elections.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, a, arr[101], ma = -1, ind = 1; 4 | int main() { 5 | cin >> n >> m; 6 | for (int i = 1; i <= m; i++) { 7 | for (int j = 1; j <= n; j++) { 8 | cin >> a; 9 | if (ma < a) { 10 | ma = a; 11 | ind = j; 12 | } 13 | } 14 | arr[ind]++; 15 | ma = -1; 16 | } 17 | for (int i = 1; i <= n; i++) { 18 | if (ma < arr[i]) { 19 | ma = arr[i]; 20 | ind = i; 21 | } 22 | } 23 | cout << ind; 24 | } -------------------------------------------------------------------------------- /572A - Arrays/572A - Arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int na, nb, k, m, ara[100001], arb[100001]; 5 | int main() { 6 | cin >> na >> nb >> k >> m; 7 | for (int i = 0; i < na; i++) { 8 | cin >> ara[i]; 9 | } 10 | for (int i = 0; i < nb; i++) { 11 | cin >> arb[i]; 12 | } 13 | reverse(arb, arb + nb); 14 | if (* max_element(ara, ara + k) < * min_element(arb, arb + m)) { 15 | cout << "YES"; 16 | } else { 17 | cout << "NO"; 18 | } 19 | } -------------------------------------------------------------------------------- /577A - Multiplication Table/577A - Multiplication Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, x, i = 1, sum = 0; 4 | int main() { 5 | cin >> n >> x; 6 | if (n < x) { 7 | i = x / n; 8 | if (x % n != 0) { 9 | i++; 10 | } 11 | } 12 | for (i; i <= n; i++) { 13 | if (x % i == 0) { 14 | sum++; 15 | } 16 | } 17 | cout << sum; 18 | } -------------------------------------------------------------------------------- /579A - Raising Bacteria/579A - Raising Bacteria.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, xar, pas; 5 | int main() { 6 | cin >> a; 7 | while (a > 0) { 8 | if (pow(2, xar) <= a) { 9 | xar++; 10 | } else { 11 | pas++; 12 | a -= pow(2, xar - 1); 13 | xar = 0; 14 | } 15 | } 16 | cout << pas; 17 | } 18 | -------------------------------------------------------------------------------- /580A - Kefa and First Steps/580A - Kefa and First Steps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int b, x, a, c = 1, d = 1; 4 | int main() { 5 | cin >> a >> b; 6 | a--; 7 | while (a--) { 8 | cin >> x; 9 | if (x >= b) { 10 | d++; 11 | } else { 12 | d = 1; 13 | } 14 | b = x; 15 | c = max(c, d); 16 | } 17 | cout << c; 18 | } -------------------------------------------------------------------------------- /581A - Vasya the Hipster/581A - Vasya the Hipster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b; 4 | int main() { 5 | cin >> a >> b; 6 | if (a < b) { 7 | cout << a << " " << (b - a) / 2; 8 | } else { 9 | cout << b << " " << (a - b) / 2; 10 | } 11 | } -------------------------------------------------------------------------------- /583A - Asphalting Roads/583A - Asphalting Roads.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, x, y, arr[51][51]; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= n * n; i++) { 7 | cin >> x >> y; 8 | if (arr[x][y] != 1) { 9 | for (int j = 1; j <= n; j++) { 10 | arr[x][j] = 1; 11 | } 12 | for (int j = 1; j <= n; j++) { 13 | arr[j][y] = 1; 14 | } 15 | cout << i << " "; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /584A - Olesya and Rodion/584A - Olesya and Rodion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a, b; 5 | string c; 6 | int main() { 7 | cin >> a >> b; 8 | if (b != 10){ 9 | for (int i = 0; i < a; i++) { 10 | cout << b; 11 | } 12 | } else if(b == 10 && a != 1) { 13 | for (int i = 1; i < a; i++) { 14 | cout << 1; 15 | } 16 | cout << 0; 17 | } else { 18 | cout << -1; 19 | } 20 | } -------------------------------------------------------------------------------- /588A - Duff and Meat/588A - Duff and Meat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, b, pr = 101, sum = 0; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a >> b; 8 | if (pr > b) { 9 | pr = b; 10 | } 11 | sum += pr * a; 12 | } 13 | cout << sum; 14 | } -------------------------------------------------------------------------------- /58A - Chat room/58A - Chat room.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a, b = "hello"; 4 | int j = 0, pas = 0; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] == b[j]) { 9 | j++; 10 | pas++; 11 | 12 | if (pas == 5) { 13 | break; 14 | } 15 | } 16 | } 17 | if (pas == 5) { 18 | cout << "YES"; 19 | } else { 20 | cout << "NO"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /58B - Coins/58B - Coins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a; 5 | int func(int k) { 6 | for (int i = 2; i <= k; i++) { 7 | if (k % i == 0) { 8 | return k / i; 9 | } 10 | } 11 | return 0; 12 | } 13 | int main() { 14 | cin >> a; 15 | while (a != 1) { 16 | cout << a << " "; 17 | a = func(a); 18 | } 19 | cout << 1; 20 | } -------------------------------------------------------------------------------- /591A - Wizards' Duel/591A - Wizards' Duel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | double a, b, c; 5 | int main() { 6 | cin >> a >> b >> c; 7 | printf("%.4f", (100 * b) / (b + c) * a / 100); 8 | } -------------------------------------------------------------------------------- /595A - Vitaly and Night/595A - Vitaly and Night.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m, a, b, ans; 4 | int main() { 5 | cin >> n >> m; 6 | for (int i = 0; i < n; i++) { 7 | for (int j = 0; j < m; j++) { 8 | cin >> a >> b; 9 | if (a == 1 || b == 1) { 10 | ans++; 11 | } 12 | } 13 | } 14 | cout << ans; 15 | } 16 | -------------------------------------------------------------------------------- /598A - Tricky Sum/598A - Tricky Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int t; 4 | __int64 n, sum, sum2, num; 5 | int main() { 6 | cin >> t; 7 | for (int i = 1; i <= t; i++) { 8 | cin >> n; 9 | num = 1; 10 | sum2 = 0; 11 | sum = n * (n + 1) / 2; 12 | while (num <= n) { 13 | sum2 += num; 14 | num *= 2; 15 | } 16 | cout << sum - sum2 * 2 << endl; 17 | } 18 | } -------------------------------------------------------------------------------- /599A - Patrick and Shopping/599A - Patrick and Shopping.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c, first, second, third, fourth; 4 | int main() { 5 | cin >> a >> b >> c; 6 | first = a + b + c; 7 | second = 2 * (a + b); 8 | third = 2 * (b + c); 9 | fourth = 2 * (a + c); 10 | cout << min(first, min(second, min(third, fourth))); 11 | } 12 | -------------------------------------------------------------------------------- /59A - Word/59A - Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int lo = 0, up = 0; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] < 97) up++; 9 | else lo++; 10 | } 11 | if (lo >= up) { 12 | for (int i = 0; i < a.size(); i++) { 13 | if (a[i] < 97) { 14 | a[i] = (char) (a[i] + 32); 15 | } 16 | } 17 | } else { 18 | for (int i = 0; i < a.size(); i++) { 19 | if (a[i] > 96) { 20 | a[i] = (char) (a[i] - 32); 21 | } 22 | } 23 | } 24 | cout << a; 25 | } -------------------------------------------------------------------------------- /611A - New Year and Days/611A - New Year and Days.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n; 4 | string a, b; 5 | int main() { 6 | cin >> n >> b >> a; 7 | if (a[0] == 'w') { 8 | if (n >= 5 && n < 7) { 9 | cout << 53; 10 | } else { 11 | cout << 52; 12 | } 13 | } else if (a[0] == 'm') { 14 | if (n <= 29) { 15 | cout << 12; 16 | } else if (n > 28 && n <= 30){ 17 | cout << 11; 18 | } else { 19 | cout << 7; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /615A - Bulbs/615A - Bulbs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, m, k[101], a, b; 5 | int main() { 6 | cin >> n >> m; 7 | for (int i = 0; i < n; i++) { 8 | cin >> a; 9 | for (int j = 0; j < a; j++) { 10 | cin >> b; 11 | k[b] = 1; 12 | } 13 | } 14 | if (* min_element(k + 1, k + m + 1) == 1) { 15 | cout << "YES"; 16 | } else { 17 | cout << "NO"; 18 | } 19 | } -------------------------------------------------------------------------------- /617A - Elephant/617A - Elephant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, pas; 4 | int main() { 5 | cin >> a; 6 | pas = a / 5; 7 | if (a % 5 > 0) { 8 | pas++; 9 | } 10 | cout << pas; 11 | } -------------------------------------------------------------------------------- /61A - Ultra-Fast Mathematician/61A - Ultra-Fast Mathematician.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a, b; 4 | int mas[105]; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] == b[i]) { 9 | mas[i] = 0; 10 | } else { 11 | mas[i] = 1; 12 | } 13 | } 14 | for (int i = 0; i < a.size(); i++) { 15 | cout << mas[i]; 16 | } 17 | } -------------------------------------------------------------------------------- /621A - Wet Shark and Odd and Even/621A - Wet Shark and Odd and Even.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, index = -1; 5 | __int64 arr[100001], pas; 6 | int main() { 7 | cin >> n; 8 | for (int i = 0; i < n; i++) { 9 | cin >> arr[i]; 10 | } 11 | sort(arr, arr + n); 12 | reverse(arr, arr + n); 13 | for (int i = 0; i < n; i++) { 14 | if (arr[i] % 2 == 0) { 15 | pas += arr[i]; 16 | } else { 17 | if (index == -1) { 18 | index = i; 19 | } else { 20 | pas += arr[index] + arr[i]; 21 | index = -1; 22 | } 23 | } 24 | } 25 | cout << pas; 26 | } -------------------------------------------------------------------------------- /62A - A Student's Dream/62A - A Student's Dream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int funq(int a, int c) { 4 | if (a < c) { 5 | if (c / (a + 1) == 1) { 6 | return 1; 7 | } else if (c / (a + 1) == 2 && c % (a + 1) == 0) { 8 | return 1; 9 | } 10 | } else if (a >= c && a - 1 <= c) { 11 | return 1; 12 | } 13 | return 0; 14 | 15 | } 16 | int a, b , c, d, pas; 17 | int main() { 18 | cin >> a >> b >> c >> d; 19 | pas = max(funq(a, d), funq(b, c)); 20 | if (pas == 1) { 21 | cout << "YES"; 22 | } else { 23 | cout << "NO"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /630A - Again Twenty Five!/630A - Again Twenty Five!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long i; 4 | int main(){ 5 | cin>>i; 6 | cout<<25; 7 | } -------------------------------------------------------------------------------- /630B - Moore's Law/630B - Moore's Law.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | double i, k; 5 | int main() { 6 | cin >> i >> k; 7 | cout << i * pow(1.000000011, k); 8 | } -------------------------------------------------------------------------------- /630C - Lucky Numbers/630C - Lucky Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | long long a, pas = 0; 5 | int main() { 6 | cin >> a; 7 | for (int i = 1; i <= a; i++) { 8 | pas += pow(2, i); 9 | } 10 | cout << pas; 11 | } -------------------------------------------------------------------------------- /630D - Hexagons!/630D - Hexagons!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long a; 4 | int main() { 5 | cin >> a; 6 | cout << ((a * (a + 1) / 2) * 6) + 1; 7 | } -------------------------------------------------------------------------------- /659A - Round House/659A - Round House.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n, a, b; 5 | int main() { 6 | cin >> n >> a >> b; 7 | if (n == 1 && a == 1 && b == 1) { 8 | cout << 1; 9 | } else { 10 | if (b > 0) { 11 | if (a + b <= n) { 12 | cout << a + b; 13 | } else { 14 | if (b <= n) { 15 | cout << b - (n - a); 16 | } else { 17 | if (a + (b % n) == n) { 18 | cout << a + (b % n); 19 | } else { 20 | cout << (a + b % n) % n; 21 | } 22 | } 23 | } 24 | } else { 25 | if (a - abs(b) > 0) { 26 | cout << a - abs(b); 27 | } else { 28 | if (abs(b) < n) { 29 | cout << n - (abs(b) - a); 30 | } else { 31 | if (abs(b) % n < a) { 32 | cout << a - (abs(b) % n); 33 | } else { 34 | cout << n - ((abs(b) % n) - a); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /672A - Summer Camp/672A - Summer Camp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n; 5 | string a; 6 | int main() { 7 | cin >> n; 8 | for (int i = 1; i <= n; i++) { 9 | a += to_string(i); 10 | } 11 | cout << a[n - 1]; 12 | } 13 | -------------------------------------------------------------------------------- /675A - Infinite Sequence/675A - Infinite Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, c; 4 | int main() { 5 | cin >> a >> b >> c; 6 | if (c == 0) { 7 | if (b == a) { 8 | cout << "YES"; 9 | } else { 10 | cout << "NO"; 11 | } 12 | } else if ((b < a && c > 0) || (b > a && c < 0)) { 13 | cout << "NO"; 14 | } else { 15 | if ((b - a) % c == 0) { 16 | cout << "YES"; 17 | } else { 18 | cout << "NO"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /676A - Nicholas and Permutation/676A - Nicholas and Permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, k, a, b; 4 | int main() { 5 | cin >> n; 6 | for (int i = 1; i <= n; i++) { 7 | cin >> k; 8 | if (k == 1) { 9 | a = i; 10 | } else if (k == n) { 11 | b = i; 12 | } 13 | } 14 | cout << max(max(n - b, b - 1), max(n - a, a - 1)); 15 | } -------------------------------------------------------------------------------- /677A - Vanya and Fence/677A - Vanya and Fence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, h, a, sum = 0; 4 | int main() { 5 | cin >> n >> h; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a; 8 | if (a > h) { 9 | sum++; 10 | } 11 | sum++; 12 | } 13 | cout << sum; 14 | } -------------------------------------------------------------------------------- /681A - A Good Contest/681A - A Good Contest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, b, d; 4 | string c; 5 | int main() { 6 | cin >> n; 7 | for (int i = 0; i < n; i++) { 8 | cin >> c >> a >> b; 9 | if (a >= 2400 && b > a) { 10 | d = 1; 11 | break; 12 | } 13 | } 14 | if (d == 1) { 15 | cout << "YES"; 16 | } else { 17 | cout << "NO"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /686A - Free Ice Cream/686A - Free Ice Cream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | __int64 n, x, d, ans; 4 | char c; 5 | int main() { 6 | cin >> n >> x; 7 | for (int i = 0; i < n; i++) { 8 | cin >> c >> d; 9 | if (c == '+') { 10 | x += d; 11 | } else if (d <= x) { 12 | x -= d; 13 | } else { 14 | ans++; 15 | } 16 | } 17 | cout << x << " " << ans; 18 | } -------------------------------------------------------------------------------- /688A - Opponents/688A - Opponents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, d, arr[101], pas, ans; 4 | string a; 5 | int main() { 6 | cin >> n >> d; 7 | for (int i = 0; i < d; i++) { 8 | cin >> a; 9 | for (int j = 0; j < n; j++) { 10 | if (a[j] == '0') { 11 | arr[i] = 1; 12 | break; 13 | } 14 | } 15 | } 16 | for (int i = 0; i < d; i++) { 17 | if (arr[i] == 1) { 18 | pas++; 19 | } else { 20 | pas = 0; 21 | } 22 | ans = max(ans, pas); 23 | } 24 | cout << ans; 25 | } -------------------------------------------------------------------------------- /688B - Lovely Palindromes/688B - Lovely Palindromes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int main() { 5 | cin >> a; 6 | for (int i = a.size() - 1; i >= 0; i--) { 7 | a += a[i]; 8 | } 9 | cout << a; 10 | } -------------------------------------------------------------------------------- /69A - Young Physicist/69A - Young Physicist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, x, y, z, x1 = 0, y1 = 0, z1 = 0; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> x >> y >> z; 8 | x1 += x; 9 | y1 += y; 10 | z1 += z; 11 | } 12 | if (x1 == 0 && y1 == 0 && z1 == 0) { 13 | cout << "YES"; 14 | } else { 15 | cout << "NO"; 16 | } 17 | } -------------------------------------------------------------------------------- /701A - Cards/701A - Cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a[101]; 4 | float av, sum; 5 | int main() { 6 | cin >> n; 7 | for (int i = 1; i <= n; i++) { 8 | cin >> a[i]; 9 | sum += a[i]; 10 | } 11 | av = (sum / n) * 2; 12 | for (int i = 1; i <= n; i++) { 13 | if (a[i] != 0) { 14 | for (int j = 1; j <= n; j++) { 15 | if (a[i] + a[j] == av && i != j) { 16 | cout << i << " " << j << endl; 17 | a[i] = 0; 18 | a[j] = 0; 19 | } 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /703A - Mishka and Game/703A - Mishka and Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, n, m, mis, cri; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | cin >> n >> m; 8 | if (n > m) { 9 | mis++; 10 | } else if(n < m) { 11 | cri++; 12 | } 13 | } 14 | if (mis > cri) { 15 | cout << "Mishka"; 16 | } else if (cri > mis) { 17 | cout << "Chris"; 18 | } else { 19 | cout << "Friendship is magic!^^"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /705A - Hulk/705A - Hulk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a; 4 | int main() { 5 | cin >> a; 6 | for (int i = 0; i < a; i++) { 7 | if (i % 2 == 0) { 8 | cout << "I hate "; 9 | } else { 10 | cout << "I love "; 11 | } 12 | if (i != a - 1) { 13 | cout << "that "; 14 | } else { 15 | cout << "it "; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /707A - Brain's Photos/707A - Brain's Photos.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | char c; 4 | int a, b, color; 5 | int main() { 6 | cin >> a >> b; 7 | for (int i = 0; i < a; i++) { 8 | for (int j = 0; j < b; j++) { 9 | cin >> c; 10 | if (c == 'C' || c == 'M' || c == 'Y') { 11 | color = 1; 12 | break; 13 | } 14 | } 15 | if (color == 1) { 16 | break; 17 | } 18 | } 19 | if (color == 1) { 20 | cout << "#Color"; 21 | } else { 22 | cout << "#Black&White"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /711A - Bus to Udayland/711A - Bus to Udayland.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, ans = 0; 4 | string c, b[1001]; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a; i++) { 8 | cin >> c; 9 | if (c[0] == 'O' && c[1] == 'O' && ans == 0) { 10 | c[0] = '+'; 11 | c[1] = '+'; 12 | ans = 1; 13 | } else if (c[3] == 'O' && c[4] == 'O'&& ans == 0) { 14 | c[3] = '+'; 15 | c[4] = '+'; 16 | ans = 1; 17 | } 18 | b[i] = c; 19 | } 20 | if (ans == 1) { 21 | cout << "YES" << endl; 22 | for (int i = 0; i < a; i++) { 23 | cout << b[i] << endl; 24 | } 25 | } else { 26 | cout << "NO"; 27 | } 28 | } -------------------------------------------------------------------------------- /716A - Crazy Computer/716A - Crazy Computer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, c, a, b, num = 1; 4 | int main() { 5 | cin >> n >> c; 6 | cin >> a; 7 | n--; 8 | while (n--) { 9 | cin >> b; 10 | if (b - a <= c) { 11 | num++; 12 | } else { 13 | num = 1; 14 | } 15 | a = b; 16 | } 17 | cout << num; 18 | } -------------------------------------------------------------------------------- /719A - Vitya in the Countryside/719A - Vitya in the Countryside.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, a, yest, tod; 4 | int main() { 5 | cin >> n; 6 | for (int i = 0; i < n; i++) { 7 | cin >> a; 8 | if (n == 1) { 9 | if (a == 15) { 10 | cout << "DOWN"; 11 | } else if (a == 0) { 12 | cout << "UP"; 13 | } else { 14 | cout << -1; 15 | } 16 | return 0; 17 | } else { 18 | if (i == n - 2) { 19 | yest = a; 20 | } else if (i == n - 1) { 21 | tod = a; 22 | } 23 | } 24 | } 25 | if (yest + 1 == tod && tod != 15 && tod != 0) { 26 | cout << "UP"; 27 | } else if (yest - 1 == tod && tod != 15 && tod != 0) { 28 | cout << "DOWN"; 29 | } else if (yest + 1 == tod && tod == 15) { 30 | cout << "DOWN"; 31 | } else if (yest - 1 == tod && tod == 0) { 32 | cout << "UP"; 33 | } else { 34 | cout << -1; 35 | } 36 | } -------------------------------------------------------------------------------- /71A - Way Too Long Words/71A - Way Too Long Words.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int n; 5 | int main() { 6 | cin >> n; 7 | for (int i = 0; i < n; i++) { 8 | cin >> a; 9 | if (a.length() > 10) { 10 | cout << a[0] << a.length() - 2 << a[a.length() - 1] << endl; 11 | } else { 12 | cout << a << endl; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /721A - One-dimensional Japanese Crossword/721A - One-dimensional Japanese Crossword.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, s = 0, arr[51], j = 0; 4 | string a; 5 | int main() { 6 | cin >> n >> a; 7 | for (int i = 0; i < n; i++) { 8 | if (a[i] == 'B') { 9 | s++; 10 | arr[j] = s; 11 | if (i == n - 1) { 12 | j++; 13 | } 14 | } else if (s != 0) { 15 | s = 0; 16 | j++; 17 | } 18 | } 19 | cout << j << endl; 20 | for (int i = 0; i < j; i++) { 21 | cout << arr[i] << " "; 22 | } 23 | } -------------------------------------------------------------------------------- /723A - The New Year Meeting Friends/723A - The New Year Meeting Friends.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int mas[3]; 5 | int main() { 6 | cin >> mas[0] >> mas[1] >> mas[2]; 7 | sort(mas, mas + 3); 8 | cout << mas[2] - mas[0]; 9 | } 10 | -------------------------------------------------------------------------------- /732A - Buy a Shovel/732A - Buy a Shovel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int k, r, h = 1, i = 0, j = 1; 4 | bool b = true; 5 | int main() { 6 | cin >> k >> r; 7 | while (b) { 8 | i++; 9 | h = k * i; 10 | if (h % 10 == 0 || h % 10 == r) { 11 | b = false; 12 | } 13 | } 14 | cout << i; 15 | } -------------------------------------------------------------------------------- /734B - Anton and Digits/734B - Anton and Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a2, a3, a5, a6, b, c; 4 | int main() { 5 | cin >> a2 >> a3 >> a5 >> a6; 6 | b = min(a2, min(a5, a6)); 7 | a2 -= b; 8 | a5 -= b; 9 | a6 -= b; 10 | c = min(a2, a3); 11 | cout << (b * 256) + (c * 32); 12 | } -------------------------------------------------------------------------------- /80A - Panoramix's Prediction/80A - Panoramix's Prediction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a, b, h = 0; 4 | int mas[16] = { 5 | 2, 6 | 3, 7 | 5, 8 | 7, 9 | 11, 10 | 13, 11 | 17, 12 | 19, 13 | 23, 14 | 29, 15 | 31, 16 | 37, 17 | 41, 18 | 43, 19 | 47 20 | }; 21 | int main() { 22 | cin >> a >> b; 23 | for (int i = 0; i < 15; i++) { 24 | if (a == mas[i] && b == mas[i + 1]) { 25 | h++; 26 | break; 27 | } 28 | } 29 | if (h == 0) { 30 | cout << "NO"; 31 | } else { 32 | cout << "YES"; 33 | } 34 | } -------------------------------------------------------------------------------- /82A - Double Cola/82A - Double Cola.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int i, n; 4 | string mas[] = { 5 | "Sheldon", 6 | "Leonard", 7 | "Penny", 8 | "Rajesh", 9 | "Howard" 10 | }; 11 | int main() { 12 | cin >> n; 13 | n--; 14 | while (n >= 5) { 15 | n = n - 5; 16 | n = n / 2; 17 | } 18 | cout << mas[n] << endl; 19 | } -------------------------------------------------------------------------------- /851A - Arpa and a research in Mexican wave/851A - Arpa and a research in Mexican wave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | #define sp system("pause") 22 | #define FOR(i,a,b) for(int i=a;i<=b;++i) 23 | #define FORD(i,a,b) for(int i=a;i>=b;--i) 24 | #define REP(i,n) FOR(i,0,(int)n-1) 25 | #define pb(x) push_back(x) 26 | #define mp(a,b) make_pair(a,b) 27 | #define MS0(x) memset(x,0,sizeof(x)) 28 | #define MS1(x) memset(x,1,sizeof(x)) 29 | #define SORT(a,n) sort(begin(a),begin(a)+n) 30 | #define REV(a,n) reverse(begin(a),begin(a)+n) 31 | #define ll long long 32 | #define pii pair 33 | #define MOD 1000000007 34 | 35 | //int a[100000]; 36 | 37 | int main(){ 38 | 39 | int n,k,t; 40 | cin>>n>>k>>t; 41 | 42 | if(t=k){ 46 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | #define sp system("pause") 22 | #define FOR(i,a,b) for(int i=a;i<=b;++i) 23 | #define FORD(i,a,b) for(int i=a;i>=b;--i) 24 | #define REP(i,n) FOR(i,0,(int)n-1) 25 | #define pb(x) push_back(x) 26 | #define mp(a,b) make_pair(a,b) 27 | #define MS0(x) memset(x,0,sizeof(x)) 28 | #define MS1(x) memset(x,1,sizeof(x)) 29 | #define SORT(a,n) sort(begin(a),begin(a)+n) 30 | #define REV(a,n) reverse(begin(a),begin(a)+n) 31 | #define ll long long 32 | #define pii pair 33 | #define MOD 1000000007 34 | 35 | //int a[100000]; 36 | 37 | int main(){ 38 | 39 | int k,n; 40 | cin>>k; 41 | int max=0; 42 | REP(i, k){ 43 | cin>>n; 44 | if(n>max){ 45 | max=n; 46 | } 47 | } 48 | if(max-25>0){ 49 | cout< 2 | using namespace std; 3 | int n, m, h = 1; 4 | int main() { 5 | cin >> n >> m; 6 | h = 1; 7 | while (h <= m) { 8 | m = m - h; 9 | h++; 10 | if (h == n + 1) { 11 | h = 1; 12 | } 13 | } 14 | cout << m; 15 | } -------------------------------------------------------------------------------- /931A - Friends Meeting/931A - Friends Meeting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | #define sp system("pause") 22 | #define FOR(i,a,b) for(int i=a;i<=b;++i) 23 | #define FORD(i,a,b) for(int i=a;i>=b;--i) 24 | #define REP(i,n) FOR(i,0,(int)n-1) 25 | #define pb(x) push_back(x) 26 | #define mp(a,b) make_pair(a,b) 27 | #define MS0(x) memset(x,0,sizeof(x)) 28 | #define MS1(x) memset(x,1,sizeof(x)) 29 | #define SORT(a,n) sort(begin(a),begin(a)+n) 30 | #define REV(a,n) reverse(begin(a),begin(a)+n) 31 | #define ll long long 32 | #define pii pair 33 | #define MOD 1000000007 34 | 35 | int main(){ 36 | 37 | int a,b; 38 | cin>>a>>b; 39 | if(abs(a-b)%2!=0){ 40 | cout<<((abs(a-b)/2)+1)*((abs(a-b)/2)+1); 41 | } 42 | else{ 43 | cout<<(abs(a-b)/2)*((abs(a-b)/2)+1); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /94A - Restoring Password/94A - Restoring Password.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a, b, mas[11], s1; 4 | int shem(string x) { 5 | for (int i = 0; i < 10; i++) { 6 | if (x == mas[i]) { 7 | return i; 8 | } 9 | } 10 | return 0; 11 | } 12 | int main() { 13 | cin >> a; 14 | for (int i = 0; i < 10; i++) { 15 | cin >> b; 16 | mas[i] = b; 17 | } 18 | for (int i = 0; i <= 70; i = i + 10) { 19 | s1 = a.substr((size_t)i, 10); 20 | cout << shem(s1); 21 | } 22 | } -------------------------------------------------------------------------------- /96A - Football/96A - Football.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string a; 4 | int b; 5 | int main() { 6 | cin >> a; 7 | for (int i = 0; i < a.size(); i++) { 8 | if (a[i] == a[i + 1]) { 9 | b++; 10 | if (b == 6) { 11 | cout << "YES"; 12 | } 13 | } else { 14 | b = 0; 15 | } 16 | } 17 | cout << "NO"; 18 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codeforces Problemset Solutions 2 | 3 | ## All of the problems are under copyright of [Codeforces.com](http://codeforces.com) 4 | 5 | All the files above have their own problem number. 6 | For example: `1A - Theatre Square.cpp` number of the problem is `1A`. 7 | You can find problems on this [link](http://codeforces.com/problemset) 8 | 9 | P.S. Use it wisely :gem: 10 | --------------------------------------------------------------------------------