├── Level 800 ├── Strange Table.py ├── Watermelon.cpp ├── Calculating Function.cpp ├── Bear and Big Brother.cpp ├── String Similarity.py ├── Wrong Subtraction.cpp ├── Elephant.cpp ├── George and Accommodation.cpp ├── Tram.cpp ├── Soldier and Bananas.cpp ├── Restoring Three Numbers.cpp ├── In Search of an Easy Problem.cpp ├── Vasya the Hipster.cpp ├── Ultra-Fast Mathematician.cpp ├── Drinks.cpp ├── Nearly Lucky Number.cpp ├── Vanya and Fence.cpp ├── Buy a Shovel.cpp ├── Magnets.cpp ├── Team.cpp ├── Translation.cpp ├── Next Round.cpp ├── Yet Another Two Integers Problem.cpp ├── Anton and Polyhedrons.cpp ├── Bit++.cpp ├── Anton and Danik.cpp ├── Way Too Long Words.cpp ├── Hit the Lottery.cpp ├── Fox And Snake.cpp ├── Arithmetic Array.cpp ├── Beautiful Matrix.cpp ├── Anton and Letters.cpp ├── Word.cpp ├── I_love_%username%.cpp ├── Fair Playoff.cpp ├── Pangram.cpp ├── Domino piling.cpp ├── Division?.cpp ├── The New Year: Meeting Friends.cpp ├── Remove Smallest.cpp ├── Amusing Joke.cpp ├── Minutes Before the New Year.cpp ├── Gregor and Cryptography.cpp ├── Stones on the Table.cpp ├── Maximum GCD.cpp ├── Word Capitalization.cpp ├── Holiday Of Equality.cpp ├── Bachgold Problem.cpp ├── Is your horseshoe on the other hoof?.cpp ├── Park Lighting.cpp ├── Magical Sticks.cpp ├── Friends and Candies.cpp ├── Sum of Round Numbers.cpp ├── Again Twenty Five!.cpp ├── Games.cpp ├── Most Unstable Array.cpp ├── Choosing Teams.cpp ├── Required Remainder.cpp ├── EhAb AnD gCd.cpp ├── Queue at the School.cpp ├── Divisibility Problem.cpp ├── Hulk.cpp ├── FashionabLee.cpp ├── Omkar and Completion.cpp ├── Odd Set.cpp ├── Cherry.cpp ├── Mahmoud and Ehab and the even-odd game.cpp ├── Triple.cpp ├── Helpful Maths.cpp ├── Maximum in Table.cpp ├── Candies and Two Sisters.cpp ├── Fafa and his Company.cpp ├── Boy or Girl.cpp ├── Dislike of Threes.cpp ├── Restore the Permutation by Merger.cpp ├── Police Recruits.cpp ├── CopyCopyCopyCopyCopy.cpp ├── Petya and Strings.cpp ├── Second-Price Auction.cpp ├── Black Square.cpp ├── Short Substrings.cpp ├── Beautiful Year.cpp ├── Floor Number.cpp ├── Special Permutation.cpp ├── Minimal Square.cpp ├── Old-Even Increments.cpp ├── Cards for Friends.cpp ├── Find The Array.cpp ├── Honest Coach.cpp ├── Vanya and Cubes.cpp ├── Add Odd or Subtract Even.cpp ├── Collecting Coins.cpp ├── Polycarp and Coins.cpp ├── Boring Apartments.cpp ├── Mishka and Game.cpp ├── Phoenix and Balance.cpp ├── Brain's Photos.cpp ├── Colorful Stones (Simplified Edition).cpp ├── Gennady and a Card Game.cpp ├── Spy Detected!.cpp ├── I Wanna Be the Guy.cpp ├── Ordinary Numbers.cpp ├── Replacing Elements.cpp ├── Do Not Be Distracted!.cpp ├── Medium Number.cpp ├── Fair Division.cpp ├── Presents.cpp ├── Arrival of the General.cpp ├── Ezzat and Two Subsequences.cpp ├── Favorite Sequence.cpp ├── Ichihime and Triangle.cpp ├── Design Tutorial: Learn from Math.cpp ├── YES or YES?.cpp ├── Vus the Cossack and a Contest.cpp ├── Codeforces Checking.cpp ├── LCM Problem.cpp ├── Borze.cpp ├── Minority.cpp ├── Average Height.cpp └── Team Composition: Programmers and Mathematicians.cpp ├── Level 900 ├── Even Odds.cpp ├── Gravity Flip.cpp ├── Chips Moving.cpp ├── Case of the Zeros and Ones.cpp ├── Twins.cpp ├── Maximums.cpp ├── Tricky Sum.cpp ├── HQ9+.cpp ├── Distance and Axis.cpp ├── Football.cpp ├── Devu, the Singer and Churu, the Joker.cpp ├── Nastya and Rice.cpp ├── Game With Sticks.cpp ├── Magic Numbers.cpp ├── Sale.cpp ├── 01 Game.cpp ├── Odd Divisor.cpp ├── Shifting Stacks.cpp ├── Business trip.cpp ├── Food Buying.cpp ├── New Year's Number.cpp ├── Orac and Factors.cpp ├── Ilya and Bank Account.cpp ├── Dubstep.cpp ├── Unique Number.cpp ├── Make Product Equal One.cpp ├── Array Reodering.cpp ├── Candies.cpp ├── Puzzles.cpp ├── Kefa and First Steps.cpp ├── Multiply by 2, divide by 6.cpp ├── Vasya and Socks.cpp ├── Construct the String.cpp ├── Lineland Mail.cpp └── Filling Diamonds.cpp ├── Level 1000 ├── Lecture.py ├── Expression.cpp ├── Young Physicist.cpp ├── Theatre Square.cpp ├── Lucky Division.cpp ├── cAPS lOCK.cpp ├── String Task.cpp ├── Chat room.cpp ├── Dragons.cpp ├── New Year Transportation.cpp ├── Road To Zero.cpp ├── Xenia and Ringroad.cpp ├── Payment Without Change.cpp ├── Move Brackets.cpp ├── Olesya and Rodion.cpp ├── Raising Bacteria.cpp ├── New Year Candles.cpp └── Bogosort.cpp ├── Level 1300 ├── IQ test.cpp ├── Reverse String.cpp └── Coin Rows.cpp ├── Level 1200 ├── Vanya and Lanterns.cpp ├── BerSU Ball.cpp ├── Fall Down.cpp ├── Cheap Travel.cpp └── Flipping Game.cpp └── Level 1100 ├── Ilya and Queries.cpp ├── Fancy Fence.cpp ├── Sum of Odd Integers.cpp └── Laptops.cpp /Level 800/Strange Table.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | while t != 0: 3 | n, m, x = map(int, input().split()) 4 | x-=1 5 | column = int(x/n) 6 | row = int(x%n) 7 | print(round(row*m + column + 1)) 8 | t-=1 9 | -------------------------------------------------------------------------------- /Level 800/Watermelon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long long n; 7 | cin >> n; 8 | if (n % 2 == 0 && n > 2) 9 | cout << "YES"; 10 | else 11 | cout << "NO"; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Level 800/Calculating Function.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | long long n; 10 | cin >> n; 11 | 12 | if (n % 2 == 0) 13 | cout << n / 2; 14 | else 15 | cout << n / 2 - n; 16 | 17 | return 0; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Level 900/Even Odds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | 7 | int main() 8 | { 9 | ll n, k; 10 | cin >> n >> k; 11 | ll n1 = (double)n / 2 + 0.5; 12 | ll n2 = n / 2; 13 | if (k <= n1) 14 | cout << k * 2 - 1; 15 | else 16 | cout << (k - n1) * 2; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Level 800/Bear and Big Brother.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int a, b; 10 | cin >> a >> b; 11 | 12 | int i = 0; 13 | while (a <= b) 14 | { 15 | a = a * 3; 16 | b = b * 2; 17 | i++; 18 | } 19 | cout << i; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Level 800/String Similarity.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | while t != 0: 3 | n = int(input()) 4 | l = list(input()) 5 | zero = 0 6 | for i in l: 7 | if i == '0': zero += 1 8 | ans = [] 9 | if zero > (2 * n - 1 - zero): 10 | for i in range (0, n): 11 | ans.append('0') 12 | else: 13 | for i in range (0, n): 14 | ans.append('1') 15 | print(''.join(ans)) 16 | t -= 1 17 | -------------------------------------------------------------------------------- /Level 800/Wrong Subtraction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | int n, k; 11 | cin >> n >> k; 12 | for (int i = 1; i <= k; i++) 13 | { 14 | if (n % 10 == 0) 15 | n = n / 10; 16 | else 17 | n--; 18 | } 19 | cout << n; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Level 1000/Lecture.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | l1 = [] 3 | l2 = [] 4 | for i in range (0, m): 5 | s = str(input()) 6 | a, b = s.split(' ', 1) 7 | l1.append(a) 8 | l2.append(b) 9 | ss = str(input()) 10 | l = ss.split() 11 | res = [] 12 | for i in range (0, n): 13 | j = l1.index(l[i]) 14 | if len(l1[j]) <= len(l2[j]): res.append(l1[j]) 15 | else: res.append(l2[j]) 16 | print(' '.join(res)) 17 | -------------------------------------------------------------------------------- /Level 800/Elephant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | int x; 9 | cin >> x; 10 | int dem = 0; 11 | if (x >= 1 && x <= 5) 12 | cout << 1; 13 | else 14 | { 15 | while (x > 5) 16 | { 17 | x = x - 5; 18 | dem++; 19 | } 20 | dem++; 21 | cout << dem; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Level 800/George and Accommodation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | int p, q; 13 | int dem = 0; 14 | 15 | for (int i = 1; i <= n; i++) 16 | { 17 | cin >> p >> q; 18 | if (q - p > 1) 19 | dem++; 20 | } 21 | cout << dem; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Level 800/Tram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | int a, b; 13 | int s = 0; 14 | int max = 0; 15 | for (int i = 1; i <= n; i++) 16 | { 17 | cin >> a >> b; 18 | s = s - a + b; 19 | if (s > max) 20 | max = s; 21 | } 22 | cout << max; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Level 800/Soldier and Bananas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int k, n, w; 10 | cin >> k >> n >> w; 11 | 12 | int s = 0; 13 | for (int i = 1; i <= w; i++) 14 | { 15 | s = s + k * i; 16 | } 17 | int t = s - n; 18 | if (t >= 0) 19 | cout << t; 20 | else 21 | cout << 0; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Level 800/Restoring Three Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | 7 | int main() 8 | { 9 | ll n = 4; 10 | ll a[4]; 11 | for (int i = 0; i < 4; i++) 12 | cin >> a[i]; 13 | sort(a, a + n); 14 | cout << (a[0] + a[1]) - a[3] << " "; 15 | cout << (a[0] + a[2]) - a[3] << " "; 16 | cout << (a[1] + a[2]) - a[3] << " "; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Level 800/In Search of an Easy Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | int a[100]; 13 | for (int i = 0; i < n; i++) 14 | { 15 | cin >> a[i]; 16 | if (a[i] == 1) 17 | { 18 | cout << "HARD"; 19 | return 0; 20 | } 21 | } 22 | cout << "EASY"; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Level 900/Gravity Flip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); cout.tie(NULL); 11 | 12 | int n; 13 | cin >> n; 14 | vectora(n); 15 | 16 | for (int i = 0; i < n; i++) 17 | cin >> a[i]; 18 | sort(a.begin(), a.end()); 19 | for (int i = 0; i < n; i++) 20 | cout << a[i] << " "; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Level 800/Vasya the Hipster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | int a, b; 12 | cin >> a >> b; 13 | 14 | int t = abs(a - b); 15 | if (t == 0) 16 | { 17 | cout << a << " " << t; 18 | return 0; 19 | } 20 | if (a > b) 21 | cout << b << " "; 22 | else 23 | cout << a << " "; 24 | cout << t / 2; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Level 800/Ultra-Fast Mathematician.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | string s, t; 12 | cin >> s; 13 | cin >> t; 14 | 15 | for (int i = 0; i < s.length(); i++) 16 | { 17 | if (s[i] != '0' && s[i] != '1') 18 | i++; 19 | if (s[i] != t[i]) 20 | cout << "1"; 21 | else 22 | cout << "0"; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Level 800/Drinks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | long long n; 12 | cin >> n; 13 | 14 | long long t; 15 | long long sum = 0; 16 | long long dem = 0; 17 | for (int i = 0; i < n; i++) 18 | { 19 | cin >> t; 20 | dem++; 21 | sum = sum + t; 22 | } 23 | cout << fixed << setprecision(12) << (double)sum / dem; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Level 800/Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | long long n; 11 | cin >> n; 12 | int dv; 13 | int dem = 0; 14 | while (n != 0) 15 | { 16 | dv = n % 10; 17 | if (dv == 4 || dv == 7) 18 | dem++; 19 | n = n / 10; 20 | } 21 | if (dem == 7 || dem == 4) 22 | cout << "YES"; 23 | else 24 | cout << "NO"; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Level 800/Vanya and Fence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n, h; 10 | cin >> n >> h; 11 | int a[1000]; 12 | 13 | for (int i = 0; i < n; i++) 14 | { 15 | cin >> a[i]; 16 | } 17 | 18 | int sum = 0; 19 | for (int i = 0; i < n; i++) 20 | { 21 | if (a[i] > h) 22 | sum = sum + 2; 23 | else 24 | sum = sum + 1; 25 | } 26 | 27 | cout << sum; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Level 800/Buy a Shovel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | 7 | int main() 8 | { 9 | ll cost, r; 10 | cin >> cost >> r; 11 | if (cost % 10 == r || cost % 10 == 0) 12 | { 13 | cout << 1; 14 | return 0; 15 | } 16 | else 17 | { 18 | ll i = 1; 19 | ll t = cost; 20 | while ((t % 10) != r && (t % 10) != 0) 21 | { 22 | t = cost * i; 23 | i++; 24 | } 25 | cout << i - 1; 26 | return 0; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Level 800/Magnets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | int n; 11 | cin >> n; 12 | 13 | int a[100000]; 14 | int p; 15 | int j = 0; 16 | 17 | for (int i = 0; i < n; i++) 18 | { 19 | cin >> p; 20 | a[j] = p; 21 | j++; 22 | } 23 | int dem = 0; 24 | for (int i = 0; i < n - 1; i++) 25 | { 26 | if (a[i] != a[i + 1]) 27 | dem++; 28 | } 29 | cout << dem + 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Level 800/Team.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | int* a = new int[3]; 13 | int dem = 0; 14 | int num = 0; 15 | for (int i = 0; i < n; i++) 16 | { 17 | for (int j = 1; j <= 3; j++) 18 | { 19 | cin >> a[j]; 20 | if (a[j] == 1) 21 | dem++; 22 | } 23 | if (dem >= 2) 24 | num++; 25 | dem = 0; 26 | } 27 | cout << num; 28 | delete[]a; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Level 900/Chips Moving.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | ll n; 16 | cin >> n; 17 | vectora(n); 18 | ll dem = 0; 19 | for (ll i = 0; i < n; i++) 20 | { 21 | cin >> a[i]; 22 | if (a[i] % 2 != 0) 23 | dem++; 24 | } 25 | cout << min(dem, n - dem); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Level 800/Translation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | string s; 12 | string t; 13 | getline(cin, s); 14 | getline(cin, t); 15 | 16 | int j = t.length() - 1; 17 | int dem = 0; 18 | for (int i = 0; i < s.length(); i++) 19 | { 20 | if (s[i] != t[j]) 21 | dem++; 22 | j--; 23 | } 24 | if (dem == 0) 25 | cout << "YES"; 26 | else 27 | cout << "NO"; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Level 800/Next Round.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n, k; 10 | cin >> n >> k; 11 | 12 | k--; 13 | int* a = new int[n]; 14 | for (int i = 0; i < n; i++) 15 | cin >> a[i]; 16 | 17 | int count = 0; 18 | for (int i = 0; i < n; i++) 19 | { 20 | if (n == 1 && a[i] != 0) 21 | count++; 22 | else if (a[i] >= a[k] && a[i] != 0) 23 | count++; 24 | } 25 | cout << count; 26 | delete[]a; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Level 800/Yet Another Two Integers Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | 7 | int main() 8 | { 9 | ll n; 10 | cin >> n; 11 | queuekq; 12 | 13 | for (ll i = 0; i < n; i++) 14 | { 15 | ll a, b; 16 | cin >> a >> b; 17 | ll n = abs(a - b); 18 | if (n % 10 == 0) 19 | n = n / 10; 20 | else 21 | n = n / 10 + 1; 22 | kq.push(n); 23 | } 24 | for (ll i = 0; i < n; i++) 25 | { 26 | cout << kq.front() << "\n"; 27 | kq.pop(); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Level 900/Case of the Zeros and Ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll n; 15 | cin >> n; 16 | string a; 17 | cin >> a; 18 | ll count_Zero = 0; 19 | for (ll i = 0; i < a.size(); i++) 20 | { 21 | if (a[i] == '0') 22 | count_Zero++; 23 | } 24 | cout << abs((a.size() - count_Zero) - count_Zero); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Level 900/Twins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | vectora(n); 12 | 13 | int sum = 0; 14 | for (int i = 0; i < n; i++) 15 | { 16 | cin >> a[i]; 17 | sum += a[i]; 18 | } 19 | sort(a.rbegin(), a.rend()); 20 | 21 | int sub = sum; 22 | int sum2 = 0; 23 | int i = 0; 24 | int count = 0; 25 | while (sum2 <= sub) 26 | { 27 | sum2 += a[i]; 28 | count++; 29 | sub = sum - sum2; 30 | i++; 31 | } 32 | cout << count; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Level 900/Maximums.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | ll n; 16 | cin >> n; 17 | vectora(n); 18 | ll x = 0; 19 | for (ll i = 0; i < n; i++) 20 | { 21 | cin >> a[i]; 22 | a[i] += x; 23 | x = max(x, a[i]); 24 | cout << a[i] << " "; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Level 800/Anton and Polyhedrons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | string s; 12 | int n; 13 | cin >> n; 14 | 15 | int sum = 0; 16 | for (int i = 0; i < n; i++) 17 | { 18 | cin >> s; 19 | if (s[0] == 84) 20 | sum += 4; 21 | if (s[0] == 67) 22 | sum += 6; 23 | if (s[0] == 79) 24 | sum += 8; 25 | if (s[0] == 68) 26 | sum += 12; 27 | if (s[0] == 73) 28 | sum += 20; 29 | } 30 | cout << sum; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Level 800/Bit++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | int x = 0; 17 | int n; 18 | cin >> n; 19 | while (n--) 20 | { 21 | string s; 22 | cin >> s; 23 | if (s == "X++") 24 | x++; 25 | else if (s == "X--") 26 | x--; 27 | else if (s == "++X") 28 | ++x; 29 | else 30 | --x; 31 | } 32 | cout << x; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Level 900/Tricky Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | ll th; 17 | cin >> th; 18 | while (th--) 19 | { 20 | ll n; 21 | cin >> n; 22 | ll sum = n * (n + 1) / 2; 23 | for (int i = 0; i < 30; i++) 24 | { 25 | if (pow(2, i) <= n) 26 | sum = sum - 2 * pow(2, i); 27 | } 28 | cout << sum << "\n"; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Level 800/Anton and Danik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | int n; 11 | string s; 12 | 13 | cin >> n; 14 | cin >> s; 15 | 16 | int countA = 0; 17 | int countD = 0; 18 | for (int i = 0; i < s.length(); i++) 19 | { 20 | if (s[i] == 'A') 21 | countA++; 22 | if (s[i] == 'D') 23 | countD++; 24 | } 25 | if (countA == countD) 26 | cout << "Friendship"; 27 | else if (countA > countD) 28 | cout << "Anton"; 29 | else 30 | cout << "Danik"; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Level 900/HQ9+.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | string a; 16 | cin >> a; 17 | bool flag = false; 18 | for (int i = 0; i < a.length(); i++) 19 | { 20 | if (a[i] == 'H' || a[i] == 'Q' || a[i] == '9') 21 | { 22 | flag = true; 23 | i = a.length(); 24 | } 25 | } 26 | if (flag == true) 27 | cout << "YES"; 28 | else 29 | cout << "NO"; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Level 900/Distance and Axis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll th; 15 | cin >> th; 16 | while (th--) 17 | { 18 | ll n, k; 19 | cin >> n >> k; 20 | 21 | if (n < k) 22 | cout << k - n; 23 | else if (n % 2 == k % 2) 24 | cout << 0; 25 | else 26 | cout << 1; 27 | cout << "\n"; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Level 800/Way Too Long Words.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); cout.tie(NULL); 11 | 12 | int n; 13 | cin >> n; 14 | 15 | queues; 16 | 17 | string a; 18 | for (int i = 0; i < n; i++) 19 | { 20 | cin >> a; 21 | s.push(a); 22 | } 23 | 24 | for (int i = 0; i < n; i++) 25 | { 26 | string a = s.front(); 27 | int n = a.length(); 28 | if (n > 10) 29 | cout << a[0] << a.length() - 2 << a[n - 1] << "\n"; 30 | else 31 | cout << a << "\n"; 32 | s.pop(); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Level 1000/Expression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main() 13 | { 14 | int a, b, c; 15 | cin >> a >> b >> c; 16 | if (a != 1 && b != 1 && c != 1) 17 | cout << a * b * c; 18 | else 19 | { 20 | vectorarr(6); 21 | arr[0] = a * b * c; 22 | arr[1] = a + b + c; 23 | arr[2] = a * b + c; 24 | arr[3] = a + b * c; 25 | arr[4] = (a + b) * c; 26 | arr[5] = a * (b + c); 27 | sort(arr.begin(), arr.end()); 28 | cout << arr[5]; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Level 800/Hit the Lottery.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | ll n; 12 | cin >> n; 13 | 14 | int count = 0; 15 | ll t = n; 16 | while (t >= 100) 17 | { 18 | t -= 100; 19 | count++; 20 | } 21 | while (t >= 20) 22 | { 23 | t -= 20; 24 | count++; 25 | } 26 | while (t >= 10) 27 | { 28 | t -= 10; 29 | count++; 30 | } 31 | while (t >= 5) 32 | { 33 | t -= 5; 34 | count++; 35 | } 36 | while (t >= 1) 37 | { 38 | t -= 1; 39 | count++; 40 | } 41 | cout << count; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 900/Football.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | string s; 11 | cin >> s; 12 | 13 | int n = s.length(); 14 | if (n <= 6) 15 | { 16 | cout << "NO"; 17 | return 0; 18 | } 19 | int sum = 0; 20 | int dem2 = 0; 21 | for (int i = 0; i <= n - 7; i++) 22 | { 23 | int flag = 1; 24 | for (int j = i; j < i + 6; j++) 25 | { 26 | if (s[j] != s[j + 1]) 27 | flag = 0; 28 | } 29 | if (flag == 1) 30 | dem2++; 31 | } 32 | if (dem2 == 0) 33 | cout << "NO"; 34 | else 35 | cout << "YES"; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Level 900/Devu, the Singer and Churu, the Joker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | int n, d; 16 | cin >> n >> d; 17 | vectora(n); 18 | int sum = 0; 19 | for (int i = 0; i < n; i++) 20 | { 21 | cin >> a[i]; 22 | sum += a[i]; 23 | } 24 | 25 | if ((n - 1) * 10 >= d || ((n - 1) * 10 + sum) > d) 26 | cout << "-1"; 27 | else 28 | { 29 | int time_sing = d - sum; 30 | cout << time_sing / 5; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Level 900/Nastya and Rice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll n; 15 | cin >> n; 16 | for (ll i = 0; i < n; i++) 17 | { 18 | ll g, a, b, c, d; 19 | cin >> g >> a >> b >> c >> d; 20 | ll sub_ab = a - b; 21 | ll sum_ab = a + b; 22 | ll sub_cd = c - d; 23 | ll sum_cd = c + d; 24 | 25 | if ((sum_ab * g < sub_cd) || (sub_ab * g > sum_cd)) 26 | cout << "No"; 27 | else 28 | cout << "Yes"; 29 | cout << "\n"; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Level 1000/Young Physicist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | int n; 17 | cin >> n; 18 | int sum0 = 0; 19 | int sum1 = 0; 20 | int sum2 = 0; 21 | 22 | while (n > 0) 23 | { 24 | vectora(3); 25 | cin >> a[0] >> a[1] >> a[2]; 26 | sum0 += a[0]; 27 | sum1 += a[1]; 28 | sum2 += a[2]; 29 | n--; 30 | } 31 | if (sum0 == 0 && sum1 == 0 && sum2 == 0) 32 | cout << "YES"; 33 | else 34 | cout << "NO"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Level 1300/IQ test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); cout.tie(0); 16 | 17 | int n; 18 | cin >> n; 19 | vectora(n); 20 | int c = 0; 21 | int l = 0; 22 | int vtc = -1; 23 | int vtl = -1; 24 | for (int i = 0; i < n; i++) 25 | { 26 | cin >> a[i]; 27 | if (a[i] % 2 == 0) 28 | { 29 | c++; 30 | vtc = i; 31 | } 32 | else 33 | vtl = i; 34 | } 35 | if (c == 1) 36 | cout << vtc + 1; 37 | else 38 | cout << vtl + 1; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Level 1000/Theatre Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | ll n, m, a; 17 | cin >> n >> m >> a; 18 | ll demr = 0; 19 | ll demd = 0; 20 | ll r = 0; 21 | ll d = 0; 22 | if (n <= a && m <= a) 23 | cout << 1; 24 | else 25 | { 26 | if (n % a == 0) 27 | demr = n / a; 28 | else 29 | demr = n / a + 1; 30 | 31 | if (m % a == 0) 32 | demd = m / a; 33 | else 34 | demd = m / a + 1; 35 | 36 | cout << demr * demd; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 900/Game With Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); cout.tie(0); 16 | 17 | int n, m; 18 | cin >> n >> m; 19 | 20 | if (n == 1 || m == 1) 21 | cout << "Akshat"; 22 | else 23 | { 24 | int t = -1; 25 | if (n < m) 26 | t = n; 27 | else 28 | t = m; 29 | if (t % 2 == 0) 30 | cout << "Malvika"; 31 | else 32 | cout << "Akshat"; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Level 800/Fox And Snake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | int n, m; 11 | cin >> n >> m; 12 | 13 | for (int i = 1; i <= n; i++) 14 | { 15 | if (i % 2 != 0) 16 | { 17 | for (int j = 1; j <= m; j++) 18 | cout << "#"; 19 | cout << "\n"; 20 | } 21 | if (i % 2 == 0) 22 | { 23 | if (i % 4 == 2) 24 | { 25 | for (int j = 1; j < m; j++) 26 | cout << "."; 27 | cout << "#"; 28 | cout << "\n"; 29 | } 30 | if (i % 4 == 0) 31 | { 32 | cout << "#"; 33 | for (int j = 2; j <= m; j++) 34 | cout << "."; 35 | cout << "\n"; 36 | } 37 | } 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Level 900/Magic Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | string a; 16 | cin >> a; 17 | bool flag = true; 18 | for (ll i = 0; i < a.size(); i++) 19 | { 20 | if (a[i] != '1' && a[i] != '4') 21 | flag = false; 22 | } 23 | if (a[0] == '4') 24 | flag = false; 25 | if (a.find("444") <= a.size()) 26 | flag = false; 27 | 28 | if (flag == true) 29 | cout << "YES"; 30 | else 31 | cout << "NO"; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Level 800/Arithmetic Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | int n; 12 | cin >> n; 13 | queuekq; 14 | 15 | for (int i = 0; i < n; i++) 16 | { 17 | int t; 18 | int sum = 0; 19 | cin >> t; 20 | vectora(t); 21 | for (int j = 0; j < t; j++) 22 | { 23 | cin >> a[j]; 24 | sum += a[j]; 25 | } 26 | if (sum == t) 27 | kq.push(0); 28 | else if (sum < t) 29 | kq.push(1); 30 | else 31 | kq.push(sum - t); 32 | } 33 | for (int i = kq.size(); i > 0; i--) 34 | { 35 | cout << kq.front() << "\n"; 36 | kq.pop(); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 900/Sale.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll n, m; 15 | cin >> n >> m; 16 | 17 | vectora(n); 18 | for (ll i = 0; i < n; i++) 19 | cin >> a[i]; 20 | 21 | sort(a.begin(), a.end()); 22 | if (a[0] >= 0) 23 | { 24 | cout << 0; 25 | return 0; 26 | } 27 | else 28 | { 29 | ll sum = 0; 30 | for (ll i = 0; i < m; i++) 31 | { 32 | if (a[i + 1] >= 0) 33 | { 34 | sum += a[i]; 35 | i = m; 36 | } 37 | else 38 | sum += a[i]; 39 | } 40 | cout << abs(sum); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 800/Beautiful Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | int a[5][5]; 12 | int vt = 0; 13 | for (int i = 0; i < 5; i++) 14 | { 15 | for (int j = 0; j < 5; j++) 16 | { 17 | cin >> a[i][j]; 18 | if (a[i][j] == 1) 19 | { 20 | vt = abs(i - j); 21 | if (i == j && i != 2 & (j == 0 || j == 4)) 22 | { 23 | vt = 4; 24 | } 25 | if (i == j && i != 2 & (j == 1 || j == 3)) 26 | { 27 | vt = 2; 28 | } 29 | if (!(i == 2 || j == 2) && vt == 1) 30 | { 31 | vt = 3; 32 | } 33 | } 34 | } 35 | cout << "\n"; 36 | } 37 | cout << vt; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Level 800/Anton and Letters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | 11 | string s; 12 | getline(cin, s); 13 | 14 | char* a = new char[s.length()]; 15 | int j = 0; 16 | int dem = 0; 17 | for (int i = 0; i < s.length(); i++) 18 | { 19 | if (s[i] >= 97 && s[i] <= 122) 20 | { 21 | a[j] = s[i]; 22 | j++; 23 | dem++; 24 | } 25 | } 26 | if (dem == 0) 27 | { 28 | cout << 0; 29 | return 0; 30 | } 31 | sort(a, a + dem); 32 | 33 | int count = 0; 34 | for (int i = 0; i < dem - 1; i++) 35 | { 36 | if (a[i] != a[i + 1]) 37 | count++; 38 | } 39 | cout << count + 1; 40 | delete[]a; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 900/01 Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll n; 15 | cin >> n; 16 | for (ll i = 0; i < n; i++) 17 | { 18 | string game; 19 | cin >> game; 20 | int c_zero = 0; 21 | for (int h = 0; h < game.size(); h++) 22 | { 23 | if (game[h] == '0') 24 | c_zero++; 25 | } 26 | int temp; 27 | if (c_zero >= (game.size() - c_zero)) 28 | temp = game.size() - c_zero; 29 | else 30 | temp = c_zero; 31 | 32 | if (temp % 2 != 0) 33 | cout << "DA"; 34 | else 35 | cout << "NET"; 36 | cout << "\n"; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 900/Odd Divisor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(0); cout.tie(0); 11 | 12 | queuekq; 13 | ll sth; 14 | cin >> sth; 15 | 16 | for (ll i = 0; i < sth; i++) 17 | { 18 | ll n; 19 | cin >> n; 20 | 21 | if (n % 2 != 0) 22 | kq.push("YES"); 23 | else 24 | { 25 | while (n > 1) 26 | { 27 | n = n / 2; 28 | if (n % 2 != 0 && n > 1) 29 | { 30 | kq.push("YES"); 31 | n = 0; 32 | } 33 | } 34 | if (n == 1) 35 | kq.push("NO"); 36 | } 37 | } 38 | for (ll i = kq.size(); i > 0; i--) 39 | { 40 | cout << kq.front() << "\n"; 41 | kq.pop(); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Level 900/Shifting Stacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | ll th; 16 | cin >> th; 17 | while (th--) 18 | { 19 | ll n; 20 | cin >> n; 21 | vectora(n); 22 | for (ll i = 0; i < n; i++) 23 | cin >> a[i]; 24 | ll sum = 0; 25 | ll t = 0; 26 | bool flag = false; 27 | for (ll i = 0; i < n; i++) 28 | { 29 | t += i; 30 | sum += a[i]; 31 | if (sum < t) 32 | { 33 | flag = true; 34 | cout << "NO\n"; 35 | i = n; 36 | } 37 | } 38 | if (flag == false) 39 | cout << "YES\n"; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 800/Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | string s; 11 | getline(cin, s); 12 | 13 | int count_a = 0; 14 | int count_A = 0; 15 | 16 | for (int i = 0; i < s.length(); i++) 17 | { 18 | if (s[i] >= 97 && s[i] <= 122) 19 | count_a++; 20 | else 21 | count_A++; 22 | } 23 | if (count_a >= count_A) 24 | { 25 | for (int i = 0; i < s.length(); i++) 26 | { 27 | if (s[i] >= 65 && s[i] <= 90) 28 | s[i] = char(s[i] + 32); 29 | } 30 | } 31 | else 32 | { 33 | for (int i = 0; i < s.length(); i++) 34 | { 35 | if (s[i] >= 97 && s[i] <= 122) 36 | s[i] = char(s[i] - 32); 37 | } 38 | } 39 | cout << s; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 1000/Lucky Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | 13 | int main() 14 | { 15 | ios_base::sync_with_stdio(false); 16 | cin.tie(0); cout.tie(0); 17 | 18 | vectora(14); 19 | a[0] = 4; 20 | a[1] = 7; 21 | a[2] = 44; 22 | a[3] = 47; 23 | a[4] = 74; 24 | a[5] = 77; 25 | a[6] = 444; 26 | a[7] = 447; 27 | a[8] = 474; 28 | a[9] = 477; 29 | a[10] = 744; 30 | a[11] = 747; 31 | a[12] = 774; 32 | a[13] = 777; 33 | 34 | int n; 35 | cin >> n; 36 | bool flag = false; 37 | for (int i = 0; i < 14; i++) 38 | if (n % a[i] == 0) 39 | flag = true; 40 | if (flag == true) 41 | cout << "YES"; 42 | else 43 | cout << "NO"; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 900/Business trip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll k; 15 | cin >> k; 16 | vectormonth(12); 17 | 18 | for (ll i = 0; i < 12; i++) 19 | cin >> month[i]; 20 | 21 | sort(month.rbegin(), month.rend()); 22 | 23 | if (k == 0) 24 | { 25 | cout << 0; 26 | return 0; 27 | } 28 | else 29 | { 30 | ll sum = 0; 31 | ll count = 0; 32 | for (ll i = 0; i < 12; i++) 33 | { 34 | if (sum < k) 35 | { 36 | sum += month[i]; 37 | count++; 38 | } 39 | else 40 | i = 12; 41 | } 42 | if (sum >= k) 43 | cout << count; 44 | else 45 | cout << -1; 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Level 800/I_love_%username%.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); cout.tie(NULL); 10 | int n; 11 | cin >> n; 12 | vectora(n); 13 | 14 | for (int i = 0; i < n; i++) 15 | { 16 | cin >> a[i]; 17 | } 18 | int min; 19 | int max; 20 | int dem = 0; 21 | if (n == 1) 22 | { 23 | cout << dem; 24 | return 0; 25 | } 26 | if (a[1] > a[0]) 27 | { 28 | min = a[0]; 29 | max = a[1]; 30 | dem++; 31 | } 32 | else if (a[1] < a[0]) 33 | { 34 | min = a[1]; 35 | max = a[0]; 36 | dem++; 37 | } 38 | for (int i = 2; i < n; i++) 39 | { 40 | if (a[i] < min) 41 | { 42 | min = a[i]; 43 | dem++; 44 | } 45 | if (a[i] > max) 46 | { 47 | max = a[i]; 48 | dem++; 49 | } 50 | } 51 | cout << dem; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Level 900/Food Buying.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll th; 15 | cin >> th; 16 | while (th--) 17 | { 18 | ll money; 19 | cin >> money; 20 | if (money < 10) 21 | cout << money; 22 | else 23 | { 24 | ll sum = 0; 25 | while (money >= 10) 26 | { 27 | int du = money % 10; 28 | ll sub_du = money - du; 29 | sum += sub_du; 30 | money = sub_du / 10 + du; 31 | } 32 | cout << sum + money; 33 | } 34 | cout << "\n"; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Level 900/New Year's Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll th; 15 | cin >> th; 16 | 17 | queuekq; 18 | for (ll k = 0; k < th; k++) 19 | { 20 | ll n; 21 | cin >> n; 22 | if (n <= 2019) 23 | kq.push("NO"); 24 | else 25 | { 26 | if (n % 2020 == 0 || n % 2021 == 0) 27 | kq.push("YES"); 28 | else 29 | { 30 | ll mod = n / 2020; 31 | ll t = n - 2020 * mod; 32 | if (t <= mod || t == 2021) 33 | kq.push("YES"); 34 | else 35 | kq.push("NO"); 36 | } 37 | } 38 | } 39 | for (ll i = kq.size(); i > 0; i--) 40 | { 41 | cout << kq.front() << "\n"; 42 | kq.pop(); 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 900/Orac and Factors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | ll th; 15 | cin >> th; 16 | while (th--) 17 | { 18 | ll n, k; 19 | cin >> n >> k; 20 | if (n % 2 == 0) 21 | cout << n + 2 * k; 22 | else 23 | { 24 | ll uoc = 0; 25 | for (ll i = 2; i <= n; i++) 26 | { 27 | if (n % i == 0) 28 | { 29 | uoc = i; 30 | i = n + 1; 31 | } 32 | } 33 | cout << n + 2 * (k - 1) + uoc; 34 | } 35 | cout << "\n"; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Level 1200/Vanya and Lanterns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); cout.tie(0); 16 | 17 | ll n, l; 18 | cin >> n >> l; 19 | vectora(n); 20 | for (ll i = 0; i < n; i++) 21 | cin >> a[i]; 22 | sort(a.begin(), a.end()); 23 | ll firstDis = a[0]; 24 | ll lastDis = l - a[n - 1]; 25 | double res = max(firstDis, lastDis); 26 | double amongLargestDis = 0; 27 | for (ll i = 0; i < n - 1; i++) 28 | if ((a[i + 1] - a[i]) > amongLargestDis) 29 | amongLargestDis = a[i + 1] - a[i]; 30 | amongLargestDis /= 2; 31 | res = max(res, amongLargestDis); 32 | string str_res = to_string(res); 33 | cout << str_res << "0000"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Level 1000/cAPS lOCK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | 13 | int main() 14 | { 15 | ios_base::sync_with_stdio(false); 16 | cin.tie(0); cout.tie(0); 17 | 18 | string s; 19 | cin >> s; 20 | string ss = s; 21 | if (97 <= s[0] && s[0] <= 122) 22 | { 23 | for (int i = 1; i < s.length(); i++) 24 | { 25 | if (s[i] > 90) 26 | { 27 | cout << ss; 28 | return 0; 29 | } 30 | else 31 | s[i] += 32; 32 | } 33 | s[0] -= 32; 34 | cout << s; 35 | } 36 | else 37 | { 38 | for (int i = 1; i < s.length(); i++) 39 | { 40 | if (s[i] > 90) 41 | { 42 | cout << ss; 43 | return 0; 44 | } 45 | else 46 | s[i] += 32; 47 | } 48 | s[0] += 32; 49 | cout << s; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 800/Fair Playoff.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); cout.tie(NULL); 11 | 12 | int n; 13 | cin >> n; 14 | queueyn; 15 | for (int i = 0; i < n; i++) 16 | { 17 | vectora(4); 18 | vectorb; 19 | for (int j = 0; j < a.size(); j++) 20 | { 21 | cin >> a[j]; 22 | b.push_back(a[j]); 23 | } 24 | sort(b.begin(), b.end()); 25 | if (a[1] > a[0]) 26 | b[0] = a[1]; 27 | else 28 | b[0] = a[0]; 29 | if (a[2] > a[3]) 30 | b[1] = a[2]; 31 | else 32 | b[1] = a[3]; 33 | 34 | sort(b.begin(), b.end()); 35 | if (b[0] != b[1] || b[2] != b[3]) 36 | yn.push("NO"); 37 | else 38 | yn.push("YES"); 39 | } 40 | for (int k = yn.size(); k > 0; k--) 41 | { 42 | cout << yn.front() << "\n"; 43 | yn.pop(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 800/Pangram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); cout.tie(NULL); 11 | 12 | int n; 13 | cin >> n; 14 | string a; 15 | cin >> a; 16 | if (n < 26) 17 | { 18 | cout << "NO"; 19 | return 0; 20 | } 21 | n = a.length(); 22 | int j = 0; 23 | char* s = new char[n]; 24 | for (int i = 0; i < n; i++) 25 | { 26 | if (a[i] < 97) 27 | a[i] = a[i] + 32; 28 | s[j] = a[i]; 29 | j++; 30 | } 31 | sort(s, s + n); 32 | if (int(s[n - 1]) - int(s[0]) < 25) 33 | { 34 | cout << "NO"; 35 | return 0; 36 | } 37 | int flag = 1; 38 | for (int i = 0; i < n - 1; i++) 39 | { 40 | if (s[i] != s[i + 1]) 41 | { 42 | if (int(s[i + 1]) - int(s[i]) != 1) 43 | flag = 0; 44 | } 45 | } 46 | if (flag == 0) 47 | cout << "NO"; 48 | else 49 | cout << "YES"; 50 | delete[]s; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 1000/String Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | string a; 17 | cin >> a; 18 | for (ll i = 0; i < a.length(); i++) 19 | if (a[i] == 'e' || a[i] == 'u' || a[i] == 'o' || a[i] == 'a' || a[i] == 'i' || a[i] == 'y' || a[i] == 'E' || a[i] == 'U' || a[i] == 'O' || a[i] == 'A' || a[i] == 'I' || a[i] == 'Y') 20 | a[i] = '0'; 21 | vectorop; 22 | ll k = 0; 23 | for (ll i = 0; i < a.size(); i++) 24 | { 25 | if (a[i] != '0') 26 | { 27 | if (a[i] <= 90) 28 | { 29 | op.push_back('.'); 30 | op.push_back(char(a[i] + 32)); 31 | } 32 | else 33 | { 34 | op.push_back('.'); 35 | op.push_back(a[i]); 36 | } 37 | } 38 | } 39 | for (char i : op) 40 | cout << i; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 900/Ilya and Bank Account.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); cout.tie(NULL); 13 | 14 | ll n; 15 | ll dem = 0; 16 | cin >> n; 17 | ll t = abs(n); 18 | ll tcpy = t; 19 | while (tcpy != 0) 20 | { 21 | tcpy = tcpy / 10; 22 | dem++; 23 | } 24 | if (n >= 10) 25 | { 26 | cout << n; 27 | return 0; 28 | } 29 | else 30 | { 31 | if (dem > 2) 32 | { 33 | ll cuoi = t / 10; 34 | int dv = t % 10; 35 | ll kecuoi = t / 100; 36 | kecuoi *= 10; 37 | kecuoi = kecuoi + dv; 38 | if (cuoi > kecuoi) 39 | cout << -kecuoi; 40 | else 41 | cout << -cuoi; 42 | } 43 | else 44 | { 45 | ll cuoi = t % 10; 46 | ll kecuoi = t / 10; 47 | if (cuoi > kecuoi) 48 | cout << -kecuoi; 49 | else 50 | cout << -cuoi; 51 | } 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Level 800/Domino piling.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | int a, b; 25 | cin >> a >> b; 26 | cout << a * b / 2; 27 | return 0; 28 | }; 29 | -------------------------------------------------------------------------------- /Level 900/Dubstep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); cout.tie(NULL); 12 | 13 | string a; 14 | cin >> a; 15 | if (a.size() <= 3) 16 | { 17 | cout << a; 18 | return 0; 19 | } 20 | for (int i = 0; i < a.size() - 2; i++) 21 | { 22 | if (a[i] == 'W') 23 | { 24 | if (a[i + 1] == 'U' and a[i + 2] == 'B') 25 | { 26 | a[i] = ' '; 27 | a[i + 1] = ' '; 28 | a[i + 2] = ' '; 29 | } 30 | else 31 | { 32 | } 33 | } 34 | else 35 | { 36 | } 37 | } 38 | queueb; 39 | for (int i = 0; i < a.size(); i++) 40 | { 41 | if (a[i] != ' ' and a[i + 1] != ' ') 42 | b.push(a[i]); 43 | else if (a[i] != ' ' and a[i + 1] == ' ') 44 | { 45 | b.push(a[i]); 46 | b.push(' '); 47 | } 48 | else 49 | { 50 | } 51 | } 52 | for (int i = b.size(); i > 0; i--) 53 | { 54 | cout << b.front(); 55 | b.pop(); 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Level 800/Division?.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 8 | #define db double 9 | #define ld long double 10 | #define ll long long 11 | #define i64 __int64 // == ll 12 | #define ull unsigned long long 13 | #define ui64 unsigned __int64 // == unsigned ll 14 | #define pq priority_queue 15 | #define sortU(v) sort(v.begin(), v.end()) 16 | #define sortD(v) sort(v.rbegin(), v.rend()) 17 | #define pll pair 18 | 19 | void SolveProblem() 20 | { 21 | ll n; cin >> n; 22 | if (n >= 1900) cout << "Division 1"; 23 | else if (1600 <= n && n <= 1899) cout << "Division 2"; 24 | else if (1400 <= n && n <= 1599) cout << "Division 3"; 25 | else cout << "Division 4"; 26 | cout << "\n"; 27 | } 28 | 29 | int main() 30 | { 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(0); cout.tie(0); 33 | _TestCases_ 34 | SolveProblem(); 35 | 36 | return 0; 37 | } 38 | 39 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 40 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 41 | -------------------------------------------------------------------------------- /Level 800/The New Year: Meeting Friends.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | vectora(3); 25 | cin >> a[0] >> a[1] >> a[2]; 26 | sort(a.begin(), a.end()); 27 | cout << a[2] - a[0]; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Level 1000/Chat room.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int main() 12 | { 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | string s; 17 | cin >> s; 18 | bool flag = false; 19 | for (int i = 0; i < s.size(); i++) 20 | { 21 | if (s[i] == 'h') 22 | { 23 | for (int j = i + 1; j < s.size(); j++) 24 | { 25 | if (s[j] == 'e') 26 | { 27 | for (int k = j + 1; k < s.size(); k++) 28 | { 29 | if (s[k] == 'l') 30 | { 31 | for (int l = k + 1; l < s.size(); l++) 32 | { 33 | if (s[l] == 'l') 34 | { 35 | for (int m = l + 1; m < s.size(); m++) 36 | { 37 | if (s[m] == 'o') 38 | { 39 | flag = true; 40 | } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | } 50 | if (flag == true) 51 | cout << "YES"; 52 | else 53 | cout << "NO"; 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 1000/Dragons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); cout.tie(0); 16 | 17 | ll s, n; 18 | cin >> s >> n; 19 | vectorx(n); 20 | vectory(n); 21 | 22 | for (ll i = 0; i < n; i++) 23 | cin >> x[i] >> y[i]; 24 | 25 | ll min_index; 26 | for (ll i = 0; i < n - 1; i++) 27 | { 28 | min_index = i; 29 | for (ll j = i + 1; j < n; j++) 30 | if (x[min_index] > x[j]) 31 | min_index = j; 32 | swap(x[min_index], x[i]); 33 | swap(y[min_index], y[i]); 34 | } 35 | ll sum = s; 36 | int flag = 1; 37 | for (ll i = 0; i < n; i++) 38 | { 39 | if (sum > x[i]) 40 | sum += y[i]; 41 | else 42 | flag = 0; 43 | } 44 | if (flag == 1) 45 | cout << "YES"; 46 | else 47 | cout << "NO"; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 900/Unique Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | int th; 16 | cin >> th; 17 | while (th--) 18 | { 19 | int x; 20 | cin >> x; 21 | if (x < 10) 22 | cout << x; 23 | else if (x > 45) 24 | cout << -1; 25 | else 26 | { 27 | stacka; 28 | int i = 9; 29 | while (x > 0) 30 | { 31 | x = x - i; 32 | if (x >= 0) 33 | a.push(to_string(i)); 34 | else 35 | a.push(to_string(x + i)); 36 | i--; 37 | } 38 | for (int st = a.size(); st > 0; st--) 39 | { 40 | cout << a.top(); 41 | a.pop(); 42 | } 43 | } 44 | cout << "\n"; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Level 800/Remove Smallest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); cout.tie(NULL); 12 | 13 | queuestr; 14 | string gg; 15 | int n; 16 | cin >> n; 17 | 18 | for (int i = 0; i < n; i++) 19 | { 20 | int k; 21 | cin >> k; 22 | vectora(k); 23 | for (int j = 0; j < k; j++) 24 | { 25 | cin >> a[j]; 26 | } 27 | if (k == 1) 28 | { 29 | gg = "YES"; 30 | str.push(gg); 31 | } 32 | else 33 | { 34 | sort(a.begin(), a.end()); 35 | int dem = 0; 36 | for (int l = 0; l < k - 1; l++) 37 | { 38 | int dis = a[l + 1] - a[l]; 39 | if (dis >= 2) 40 | { 41 | gg = "NO"; 42 | str.push(gg); 43 | l = k - 1; 44 | } 45 | else 46 | { 47 | dem++; 48 | } 49 | } 50 | if (dem == k - 1) 51 | { 52 | gg = "YES"; 53 | str.push(gg); 54 | } 55 | } 56 | } 57 | for (int i = 0; i < n; i++) 58 | { 59 | cout << str.front() << "\n"; 60 | str.pop(); 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Level 800/Amusing Joke.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); cout.tie(NULL); 11 | 12 | string s1, s2, s3; 13 | cin >> s1; 14 | cin >> s2; 15 | cin >> s3; 16 | 17 | int n1, n2, n3; 18 | n1 = s1.length(); 19 | n2 = s2.length(); 20 | n3 = s3.length(); 21 | 22 | if (n1 + n2 != n3) 23 | { 24 | cout << "NO"; 25 | return 0; 26 | } 27 | 28 | char* a = new char[n3]; 29 | char* b = new char[n3]; 30 | 31 | int j1 = 0; 32 | int j2 = n1; 33 | 34 | for (int i = 0; i < n1; i++) 35 | { 36 | a[j1] = s1[i]; 37 | j1++; 38 | } 39 | for (int i = 0; i < n3 - n1; i++) 40 | { 41 | a[j2] = s2[i]; 42 | j2++; 43 | } 44 | 45 | sort(a, a + n3); 46 | 47 | for (int i = 0; i < n3; i++) 48 | { 49 | b[i] = s3[i]; 50 | } 51 | 52 | sort(b, b + n3); 53 | 54 | int flag = 1; 55 | for (int i = 0; i < n3; i++) 56 | { 57 | if (a[i] != b[i]) 58 | flag = 0; 59 | } 60 | 61 | if (flag == 0) 62 | cout << "NO"; 63 | else 64 | cout << "YES"; 65 | 66 | delete[]a; 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /Level 800/Minutes Before the New Year.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | ll th; 25 | cin >> th; 26 | while (th--) 27 | { 28 | ll h, m; 29 | cin >> h >> m; 30 | cout << 24 * 60 - (h * 60 + m) << "\n"; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Level 900/Make Product Equal One.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | ll n; 16 | cin >> n; 17 | vectora(n); 18 | 19 | bool check_Zero = false; 20 | ll sum = 0; 21 | ll dem = 0; 22 | for (ll i = 0; i < n; i++) 23 | { 24 | cin >> a[i]; 25 | if (a[i] == 0) 26 | { 27 | check_Zero = true; 28 | sum += 1; 29 | } 30 | else 31 | { 32 | if (a[i] < 0) 33 | { 34 | sum += abs(a[i]) - 1; 35 | dem++; 36 | } 37 | else 38 | sum += a[i] - 1; 39 | } 40 | } 41 | if (dem % 2 == 0) 42 | cout << sum; 43 | else 44 | { 45 | if (check_Zero == false) 46 | cout << sum + 2; 47 | else 48 | cout << sum; 49 | } 50 | 51 | return 0; 52 | }; 53 | -------------------------------------------------------------------------------- /Level 900/Array Reodering.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | int GCD(int a, int b) 12 | { 13 | while (b) 14 | { 15 | a = a % b; 16 | swap(a, b); 17 | } 18 | return a; 19 | } 20 | int LCM(int a, int b) 21 | { 22 | return (a * b) / GCD(a, b); 23 | } 24 | int main() 25 | { 26 | ios_base::sync_with_stdio(false); 27 | cin.tie(0); cout.tie(0); 28 | 29 | int th; 30 | cin >> th; 31 | while (th--) 32 | { 33 | int n; 34 | cin >> n; 35 | vectora(n); 36 | vectorb(n, 0); 37 | 38 | int dau = 0; 39 | int cuoi = n - 1; 40 | for (int i = 0; i < n; i++) 41 | { 42 | cin >> a[i]; 43 | if (a[i] % 2 == 0) 44 | { 45 | b[dau] = a[i]; 46 | dau++; 47 | } 48 | else 49 | { 50 | b[cuoi] = a[i]; 51 | cuoi--; 52 | } 53 | } 54 | int dem = 0; 55 | for (int i = 0; i < n - 1; i++) 56 | for (int j = i + 1; j < n; j++) 57 | if (GCD(b[i], 2 * b[j]) != 1) 58 | dem++; 59 | cout << dem << "\n"; 60 | } 61 | return 0; 62 | }; 63 | -------------------------------------------------------------------------------- /Level 800/Gregor and Cryptography.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | cout << 2 << " " << n - 1 << "\n"; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Level 800/Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | int n; 25 | cin >> n; 26 | string s; 27 | cin >> s; 28 | int dem = 0; 29 | for (int i = 0; i < s.length() - 1; i++) 30 | if (s[i] == s[i + 1]) 31 | dem++; 32 | cout << dem; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Level 1000/New Year Transportation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | ll BinarySearch(vector& arr, ll xx) 12 | { 13 | ll left = 0; 14 | ll right = arr.size() - 1; 15 | while (left <= right) 16 | { 17 | ll mid = (left + right) / 2; 18 | 19 | if (arr[mid] == xx) 20 | return mid; 21 | if (arr[mid] > xx) 22 | right = mid - 1; 23 | if (arr[mid] < xx) 24 | left = mid + 1; 25 | } 26 | return -1; 27 | } 28 | int main() 29 | { 30 | ll n, t; 31 | cin >> n >> t; 32 | vectora(n); 33 | vectorb; 34 | 35 | a[0] = 0; 36 | for (ll i = 1; i < n; i++) 37 | cin >> a[i]; 38 | 39 | ll vt_i = 1; 40 | while (vt_i < n) 41 | { 42 | ll res; 43 | res = vt_i + a[vt_i]; 44 | vt_i = res; 45 | b.push_back(res); 46 | } 47 | sort(b.begin(), b.end()); 48 | if (BinarySearch(b, t) != -1) 49 | cout << "YES"; 50 | else 51 | cout << "NO"; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Level 900/Candies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | ll BinarySearch(vector& arr, ll xx) 12 | { 13 | ll left = 0; 14 | ll right = arr.size() - 1; 15 | while (left <= right) 16 | { 17 | ll mid = (left + right) / 2; 18 | 19 | if (arr[mid] == xx) 20 | return mid; 21 | if (arr[mid] > xx) 22 | right = mid - 1; 23 | if (arr[mid] < xx) 24 | left = mid + 1; 25 | } 26 | return -1; 27 | } 28 | int main() 29 | { 30 | ll th; 31 | cin >> th; 32 | while (th--) 33 | { 34 | ll n; 35 | cin >> n; 36 | ll sum = 3; 37 | ll i = 1; 38 | while (sum <= n) 39 | { 40 | if (n % sum == 0) 41 | { 42 | cout << n / sum; 43 | sum = n + 1; 44 | } 45 | else 46 | { 47 | i++; 48 | sum = sum + pow(2, i); 49 | } 50 | } 51 | cout << "\n"; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Level 800/Maximum GCD.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | if (n % 2 == 0) 34 | cout << n / 2; 35 | else 36 | cout << (n - 1) / 2; 37 | cout << "\n"; 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Level 800/Word Capitalization.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | ios_base::sync_with_stdio(false); 20 | cin.tie(NULL); cout.tie(NULL); 21 | 22 | string str; 23 | getline(cin, str); 24 | 25 | 26 | if (str[0] >= 97 && str[0] <= 122) 27 | cout << char(str[0] - 32); 28 | else 29 | cout << char(str[0]); 30 | for (int i = 1; i < str.length(); i++) 31 | { 32 | cout << str[i]; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Level 800/Holiday Of Equality.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ll n; 22 | cin >> n; 23 | vectora(n); 24 | for (ll i = 0; i < n; i++) 25 | cin >> a[i]; 26 | sort(a.begin(), a.end()); 27 | ll sum = 0; 28 | for (ll i = 0; i < n - 1; i++) 29 | if (a[i] < a[n - 1]) 30 | sum = sum + (a[n - 1] - a[i]); 31 | cout << sum; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Level 800/Bachgold Problem.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int n; 28 | cin >> n; 29 | cout << n / 2 << "\n"; 30 | for (int i = 1; i < n / 2; i++) 31 | cout << 2 << " "; 32 | if (n % 2 == 0) 33 | cout << 2; 34 | else 35 | cout << 3; 36 | cout << "\n"; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Level 800/Is your horseshoe on the other hoof?.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | vectora(4); 26 | cin >> a[0] >> a[1] >> a[2] >> a[3]; 27 | sort(a.begin(), a.end()); 28 | int dem = 0; 29 | for (int i = 0; i < 3; i++) 30 | { 31 | if (a[i] != a[i + 1]) 32 | dem++; 33 | } 34 | cout << 4 - dem - 1; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Level 800/Park Lighting.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | #define MAX 100000 20 | #define MIN -100000 21 | #define ll long long 22 | 23 | void SolveProblem() 24 | { 25 | int n, m; 26 | cin >> n >> m; 27 | cout << (n * m + 1) / 2 << "\n"; 28 | } 29 | int main() 30 | { 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(0); cout.tie(0); 33 | 34 | int th; 35 | cin >> th; 36 | while (th--) 37 | SolveProblem(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 800/Magical Sticks.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | ll ans = n / 2; 34 | if (n % 2 == 0) 35 | cout << ans; 36 | else 37 | cout << ans + 1; 38 | cout << "\n"; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Level 800/Friends and Candies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | queueb; 12 | for (int k = 0; k < n; k++) 13 | { 14 | int t; 15 | int sum = 0; 16 | cin >> t; 17 | vectora(t); 18 | for (int i = 0; i < t; i++) 19 | { 20 | cin >> a[i]; 21 | sum = sum + a[i]; 22 | } 23 | if (t == 1) 24 | b.push(0); 25 | else if (t == 2) 26 | { 27 | if (a[0] == a[1]) 28 | b.push(0); 29 | else if (a[0] != a[1] && sum % t == 0) 30 | b.push(1); 31 | else if (a[0] != a[1] && sum % t != 0) 32 | b.push(-1); 33 | } 34 | else 35 | { 36 | if (sum % t != 0) 37 | b.push(-1); 38 | else 39 | { 40 | sort(a.rbegin(), a.rend()); 41 | if (a[0] == a[t - 1]) 42 | b.push(0); 43 | else 44 | { 45 | int dem = 0; 46 | int tb = sum / t; 47 | for (int c = 0; c < a.size(); c++) 48 | { 49 | if (a[c] > tb) 50 | dem++; 51 | else 52 | { } 53 | } 54 | b.push(dem); 55 | } 56 | } 57 | } 58 | } 59 | for (int d = b.size(); d > 0; d--) 60 | { 61 | cout << b.front() << "\n"; 62 | b.pop(); 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Level 800/Sum of Round Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int CountNum(int k) 11 | { 12 | int dem = 0; 13 | while (k != 0) 14 | { 15 | k = k / 10; 16 | dem++; 17 | } 18 | return dem; 19 | } 20 | void PhanTich(int x) 21 | { 22 | stackq; 23 | queuer; 24 | int dv; 25 | int count = CountNum(x); 26 | while (x != 0) 27 | { 28 | int dv = x % 10; 29 | q.push(dv); 30 | x /= 10; 31 | } 32 | int dem = 0; 33 | int value; 34 | for (int i = count - 1; i >= 0; i--) 35 | { 36 | value = q.top() * pow(10, i); 37 | if (value != 0) 38 | { 39 | r.push(value); 40 | dem++; 41 | } 42 | q.pop(); 43 | } 44 | cout << dem << "\n"; 45 | for (int j = r.size(); j > 0; j--) 46 | { 47 | cout << r.front() << " "; 48 | r.pop(); 49 | } 50 | } 51 | int main() 52 | { 53 | ios_base::sync_with_stdio(false); 54 | cin.tie(NULL); cout.tie(NULL); 55 | 56 | int n; 57 | cin >> n; 58 | vectora(n); 59 | for (int i = 0; i < n; i++) 60 | { 61 | cin >> a[i]; 62 | } 63 | for (int i = 0; i < n; i++) 64 | { 65 | PhanTich(a[i]); 66 | cout << "\n"; 67 | } 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Level 800/Again Twenty Five!.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | string n; 29 | cin >> n; 30 | cout << 25; 31 | } 32 | int main() 33 | { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); cout.tie(0); 36 | //ll th; 37 | //cin >> th; 38 | //while (th--) 39 | SolveProblem(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Level 800/Games.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | int n; 26 | cin >> n; 27 | vectora(2 * n); 28 | for (int i = 0; i < 2 * n; i++) 29 | cin >> a[i]; 30 | 31 | int count = 0; 32 | for (int i = 0; i < 2 * n - 1; i += 2) 33 | for (int j = 1; j < 2 * n; j += 2) 34 | if (a[i] == a[j]) 35 | count++; 36 | 37 | cout << count; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 800/Most Unstable Array.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n, m; 32 | cin >> n >> m; 33 | if (n == 1) 34 | cout << 0; 35 | else if (n == 2) 36 | cout << m; 37 | else 38 | cout << 2 * m; 39 | cout << "\n"; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 800/Choosing Teams.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | int n, k; 25 | cin >> n >> k; 26 | vectora(n); 27 | int ans = 0; 28 | for (int i = 0; i < n; i++) 29 | { 30 | cin >> a[i]; 31 | if (5 - a[i] >= k) 32 | ans++; 33 | } 34 | cout << ans / 3; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Level 800/Required Remainder.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll x, y, n; 32 | cin >> x >> y >> n; 33 | 34 | ll div = n / x; 35 | ll res = div * x + y; 36 | while (res > n) 37 | res -= x; 38 | cout << res; 39 | cout << "\n"; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 800/EhAb AnD gCd.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll x; 30 | cin >> x; 31 | cout << 1 << " " << x - 1; 32 | cout << "\n"; 33 | } 34 | int main() 35 | { 36 | ios_base::sync_with_stdio(false); 37 | cin.tie(0); cout.tie(0); 38 | ll th; 39 | cin >> th; 40 | while (th--) 41 | SolveProblem(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 800/Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | int n, t; 26 | cin >> n >> t; 27 | string s; 28 | cin >> s; 29 | for (int tg = 1; tg <= t; tg++) 30 | { 31 | for (int i = 0; i < s.size(); i++) 32 | { 33 | if (s[i] == 'B' && s[i + 1] == 'G') 34 | { 35 | swap(s[i], s[i + 1]); 36 | i++; 37 | } 38 | } 39 | } 40 | cout << s; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 900/Puzzles.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*------------------------------------------------------------------------* 3 | | User: Huynh Viet Tuan Kiet | 4 | | Degree: Student - Formal University | 5 | | Study Computer Science at the University of Information Technology | 6 | | Country: Viet Nam | 7 | | City: Ho Chi Minh | 8 | | Organization: VNUHCM - UIT - University of Information Technology | 9 | *-------------------------------------------------------------------------*/ 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | typedef long long ll; 20 | 21 | int main() 22 | { 23 | ios_base::sync_with_stdio(false); 24 | cin.tie(0); cout.tie(0); 25 | 26 | int n, m; 27 | cin >> n >> m; 28 | vectora(m); 29 | for (int i = 0; i < m; i++) 30 | cin >> a[i]; 31 | 32 | sort(a.begin(), a.end()); 33 | int lc = a[n - 1] - a[0]; 34 | for (int i = 0; i <= m - n; i++) 35 | if ((a[i + n - 1] - a[i]) < lc) 36 | lc = a[i + n - 1] - a[i]; 37 | cout << lc; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Level 800/Divisibility Problem.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | ll th; 26 | cin >> th; 27 | while (th--) 28 | { 29 | ll a, b; 30 | ll res; 31 | cin >> a >> b; 32 | if (a % b == 0) 33 | res = 0; 34 | else if (b > a) 35 | res = b - a; 36 | else 37 | { 38 | ll s = b * (a / b + 1); 39 | res = s - a; 40 | } 41 | cout << res << "\n"; 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Level 800/Hulk.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | 21 | int main() 22 | { 23 | ios_base::sync_with_stdio(false); 24 | cin.tie(0); cout.tie(0); 25 | 26 | string love = "I love that "; 27 | string hate = "I hate that "; 28 | int n; 29 | cin >> n; 30 | for (int i = 1; i < n; i++) 31 | { 32 | if (i % 2 == 0) 33 | cout << love; 34 | else 35 | cout << hate; 36 | } 37 | if (n % 2 == 0) 38 | cout << "I love it"; 39 | else 40 | cout << "I hate it"; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 800/FashionabLee.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 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 MAX 1000000000 22 | #define MIN -100000 23 | #define ll long long 24 | 25 | void SolveProblem() 26 | { 27 | ll n; 28 | cin >> n; 29 | if (n % 4 == 0) 30 | cout << "YES"; 31 | else 32 | cout << "NO"; 33 | cout << "\n"; 34 | } 35 | int main() 36 | { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); cout.tie(0); 39 | ll th; 40 | cin >> th; 41 | while (th--) 42 | SolveProblem(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Level 800/Omkar and Completion.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | int n; 30 | cin >> n; 31 | for (int i = 0; i < n; i++) 32 | cout << 1 << " "; 33 | cout << "\n"; 34 | } 35 | int main() 36 | { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); cout.tie(0); 39 | ll th; 40 | cin >> th; 41 | while (th--) 42 | SolveProblem(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Level 900/Kefa and First Steps.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*------------------------------------------------------------------------* 3 | | User: Huynh Viet Tuan Kiet | 4 | | Degree: Student - Formal University | 5 | | Study Computer Science at the University of Information Technology | 6 | | Country: Viet Nam | 7 | | City: Ho Chi Minh | 8 | | Organization: VNUHCM - UIT - University of Information Technology | 9 | *-------------------------------------------------------------------------*/ 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | typedef long long ll; 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | ll n; 26 | cin >> n; 27 | vectora(n); 28 | ll k = 1; 29 | ll ln = 0; 30 | for (ll i = 0; i < n; i++) 31 | cin >> a[i]; 32 | for (ll i = 1; i < n; i++) 33 | { 34 | if (a[i] >= a[i - 1]) 35 | k++; 36 | else 37 | { 38 | ln = max(ln, k); 39 | k = 1; 40 | } 41 | } 42 | ln = max(ln, k); 43 | cout << ln; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 800/Odd Set.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | ll th; 25 | cin >> th; 26 | while (th--) 27 | { 28 | ll n; 29 | cin >> n; 30 | ll mul = 2 * n; 31 | vectora(mul); 32 | ll dem = 0; 33 | for (ll i = 0; i < mul; i++) 34 | { 35 | cin >> a[i]; 36 | if (a[i] % 2 == 0) 37 | dem++; 38 | } 39 | if (dem == (mul - dem)) 40 | cout << "Yes\n"; 41 | else 42 | cout << "No\n"; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 800/Cherry.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | vectora(n); 34 | for (ll i = 0; i < n; i++) 35 | cin >> a[i]; 36 | ll lc = 0; 37 | for (ll i = 0; i < n - 1; i++) 38 | if (a[i] * a[i + 1] > lc) 39 | lc = a[i] * a[i + 1]; 40 | cout << lc << "\n"; 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 800/Mahmoud and Ehab and the even-odd game.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll n; 30 | cin >> n; 31 | if (n % 2 == 0) 32 | cout << "Mahmoud"; 33 | else 34 | cout << "Ehab"; 35 | } 36 | int main() 37 | { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(0); cout.tie(0); 40 | /*ll th; 41 | cin >> th; 42 | while (th--)*/ 43 | SolveProblem(); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 800/Triple.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | void SolveProblem() 18 | { 19 | ll n; cin >> n; 20 | vectora(n); 21 | for (ll i = 0; i < n; i++) cin >> a[i]; 22 | sortU(a); 23 | vectorcheck; 24 | check.push_back(a[0]); 25 | ll count = 1; 26 | ll res = -1; 27 | for (ll i = 1; i < n; i++) 28 | { 29 | if (a[i] == check.back()) count++; 30 | else 31 | { 32 | check.push_back(a[i]); 33 | count = 1; 34 | } 35 | if (count == 3) res = a[i]; 36 | } 37 | cout << res << "\n"; 38 | } 39 | 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | _TestCases_ 45 | SolveProblem(); 46 | 47 | return 0; 48 | } 49 | 50 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 51 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 52 | -------------------------------------------------------------------------------- /Level 800/Helpful Maths.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | ios_base::sync_with_stdio(false); 18 | cin.tie(NULL); cout.tie(NULL); 19 | 20 | string s; 21 | getline(cin, s); 22 | 23 | 24 | int* a = new int[100]; 25 | int n = s.length(); 26 | int j = 0; 27 | int num = 0; 28 | for (int i = 0; i < n; i++) 29 | { 30 | if (s[i] >= '1' && s[i] <= '3') 31 | { 32 | num++; 33 | a[j] = s[i] - '0'; 34 | j++; 35 | } 36 | } 37 | 38 | sort(a, a + num); 39 | for (int i = 0; i < num - 1; i++) 40 | { 41 | cout << a[i] << "+"; 42 | } 43 | cout << a[num - 1]; 44 | 45 | delete[]a; 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Level 800/Maximum in Table.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | #define MAX 100000 20 | #define MIN -100000 21 | #define ll long long 22 | 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(0); cout.tie(0); 27 | 28 | int n; 29 | cin >> n; 30 | vector>a(n, vector(n)); 31 | for (int i = 0; i < n; i++) 32 | { 33 | a[0][i] = 1; 34 | a[i][0] = 1; 35 | } 36 | for (int i = 1; i < n; i++) 37 | for (int j = 1; j < n; j++) 38 | a[i][j] = a[i - 1][j] + a[i][j - 1]; 39 | cout << a[n - 1][n - 1]; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Level 800/Candies and Two Sisters.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | ll th; 26 | cin >> th; 27 | while (th--) 28 | { 29 | ll n; 30 | cin >> n; 31 | if (n <= 2) 32 | cout << 0; 33 | else 34 | { 35 | if (n % 2 == 0) 36 | cout << n / 2 - 1; 37 | else 38 | cout << n / 2; 39 | } 40 | cout << "\n"; 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 1000/Road To Zero.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll x, y, a, b; 30 | cin >> x >> y >> a >> b; 31 | if (2 * a <= b) 32 | cout << (x + y) * a; 33 | else 34 | cout << min(x, y) * b + abs(x - y) * a; 35 | cout << "\n"; 36 | } 37 | int main() 38 | { 39 | ios_base::sync_with_stdio(false); 40 | cin.tie(0); cout.tie(0); 41 | ll th; 42 | cin >> th; 43 | while (th--) 44 | SolveProblem(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 800/Fafa and his Company.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | ll n, t = 1, dem = 0; 29 | cin >> n; 30 | n--; 31 | while (n > n / 2) 32 | { 33 | if (n % t == 0) 34 | dem++; 35 | n--; 36 | t++; 37 | } 38 | cout << dem; 39 | } 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | //ll th; 45 | //cin >> th; 46 | //while (th--) 47 | SolveProblem(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 800/Boy or Girl.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | cin.tie(NULL); cout.tie(NULL); 18 | 19 | string s; 20 | getline(cin, s); 21 | 22 | char* a = new char[s.length()]; 23 | int j = 0; 24 | int dem = 0; 25 | for (int i = 0; i < s.length(); i++) 26 | { 27 | a[j] = s[i]; 28 | j++; 29 | dem++; 30 | } 31 | 32 | sort(a, a + dem); 33 | 34 | int count = 0; 35 | for (int i = 0; i < dem - 1; i++) 36 | { 37 | if (a[i] != a[i + 1]) 38 | count++; 39 | } 40 | int c = count + 1; 41 | 42 | if (c % 2 == 0) 43 | cout << "CHAT WITH HER!"; 44 | else 45 | cout << "IGNORE HIM!"; 46 | 47 | delete[]a; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 800/Dislike of Threes.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | ll k; 29 | cin >> k; 30 | ll t = 1; 31 | ll c = 0; 32 | while (c < k) 33 | { 34 | if (t % 3 != 0 && t % 10 != 3) 35 | c++; 36 | t++; 37 | } 38 | cout << t - 1 << "\n"; 39 | } 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | ll th; 45 | cin >> th; 46 | while (th--) 47 | SolveProblem(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 800/Restore the Permutation by Merger.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | vectora(2 * n); 34 | vectorb(n + 1, -1); 35 | for (int i = 0; i < 2 * n; i++) 36 | { 37 | cin >> a[i]; 38 | if (b[a[i]] == -1) 39 | b[a[i]] = i; 40 | else 41 | cout << a[i] << " "; 42 | } 43 | cout << "\n"; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 1000/Xenia and Ringroad.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | ll n, m; 27 | cin >> n >> m; 28 | vectora(m); 29 | for (ll i = 0; i < m; i++) 30 | cin >> a[i]; 31 | 32 | ll ans = 0; 33 | ll k = 1; 34 | for (ll i = 0; i < m; i++) 35 | { 36 | if (a[i] == k) 37 | continue; 38 | if (a[i] > k) 39 | ans += a[i] - k; 40 | if (a[i] < k) 41 | ans += a[i] + (n - k); 42 | k = a[i]; 43 | } 44 | cout << ans; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 800/Police Recruits.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | ll n; 25 | cin >> n; 26 | vectora(n); 27 | ll toipham = 0; 28 | ll canhsat = 0; 29 | ll dem = 0; 30 | for (ll i = 0; i < n; i++) 31 | cin >> a[i]; 32 | for (ll i = 0; i < n; i++) 33 | { 34 | if (a[i] > 0) 35 | canhsat += a[i]; 36 | else 37 | { 38 | toipham = 1; 39 | if (canhsat >= 1) 40 | canhsat -= 1; 41 | else 42 | dem++; 43 | toipham = 0; 44 | } 45 | } 46 | cout << dem; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Level 800/CopyCopyCopyCopyCopy.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll n; 30 | cin >> n; 31 | vectora(n); 32 | setse; 33 | for (ll i = 0; i < n; i++) 34 | { 35 | cin >> a[i]; 36 | se.insert(a[i]); 37 | } 38 | cout << se.size() << "\n"; 39 | } 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | ll th; 45 | cin >> th; 46 | while (th--) 47 | SolveProblem(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 800/Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | string s1, s2; 25 | cin >> s1 >> s2; 26 | int flag = 0; 27 | for (int i = 0; i < s1.size(); i++) 28 | { 29 | if (s1[i] <= 90) 30 | s1[i] += 32; 31 | if (s2[i] <= 90) 32 | s2[i] += 32; 33 | if (s1[i] > s2[i]) 34 | { 35 | flag = 1; 36 | i = s1.size(); 37 | } 38 | else if (s1[i] < s2[i]) 39 | { 40 | flag = -1; 41 | i = s1.size(); 42 | } 43 | else 44 | { } 45 | } 46 | cout << flag; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Level 800/Second-Price Auction.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | 21 | int main() 22 | { 23 | ios_base::sync_with_stdio(false); 24 | cin.tie(0); cout.tie(0); 25 | 26 | int n; 27 | cin >> n; 28 | vectora(n); 29 | int lc = 0; 30 | int vt_max = -1; 31 | for (int i = 0; i < n; i++) 32 | { 33 | cin >> a[i]; 34 | if (a[i] > lc) 35 | { 36 | lc = a[i]; 37 | vt_max = i; 38 | } 39 | } 40 | sort(a.begin(), a.end()); 41 | cout << vt_max + 1 << " " << a[n - 2]; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Level 800/Black Square.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | vectora(4); 28 | cin >> a[0] >> a[1] >> a[2] >> a[3]; 29 | string s; 30 | cin >> s; 31 | ll n = s.length(); 32 | ll res = 0; 33 | for (int i = 0; i < n; i++) 34 | { 35 | if (s[i] == '1') 36 | res += a[0]; 37 | else if (s[i] == '2') 38 | res += a[1]; 39 | else if (s[i] == '3') 40 | res += a[2]; 41 | else 42 | res += a[3]; 43 | } 44 | cout << res; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 800/Short Substrings.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | int th; 25 | cin >> th; 26 | while (th--) 27 | { 28 | string s; 29 | cin >> s; 30 | int n = s.length(); 31 | cout << s[0]; 32 | for (int i = 1; i < n - 1; i += 2) 33 | cout << s[i]; 34 | cout << s[n - 1]; 35 | cout << "\n"; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Level 800/Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | bool BeauYear(int y) 21 | { 22 | int a = y % 10; 23 | int b = (y / 10) % 10; 24 | int c = (y / 100) % 10; 25 | int d = (y / 1000) % 10; 26 | if (a != b && a != c && a != d && b != c && b != d && c != d) 27 | return true; 28 | return false; 29 | } 30 | int main() 31 | { 32 | ios_base::sync_with_stdio(false); 33 | cin.tie(0); cout.tie(0); 34 | 35 | int year; 36 | cin >> year; 37 | for (int i = year + 1; i <= 9012; i++) 38 | { 39 | if (BeauYear(i) == true) 40 | { 41 | cout << i; 42 | i = 9013; 43 | } 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Level 800/Floor Number.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | #define MAX 100000 20 | #define MIN -100000 21 | #define ll long long 22 | 23 | void SolveProblem() 24 | { 25 | int n, x; 26 | cin >> n >> x; 27 | if (n == 1 || n == 2) 28 | cout << 1; 29 | else 30 | { 31 | n -= 2; 32 | int floor = n / x; 33 | if (floor * x == n) 34 | cout << floor + 1; 35 | else 36 | cout << floor + 2; 37 | } 38 | cout << "\n"; 39 | } 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | 45 | int th; 46 | cin >> th; 47 | while (th--) 48 | SolveProblem(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Level 900/Multiply by 2, divide by 6.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | int c1 = 0, c2 = 0; 34 | while (n % 2 == 0) 35 | { 36 | n /= 2; 37 | c1++; 38 | } 39 | while (n % 3 == 0) 40 | { 41 | n /= 3; 42 | c2++; 43 | } 44 | if (n == 1 && c1 <= c2) 45 | cout << 2 * c2 - c1; 46 | else 47 | cout << -1; 48 | cout << "\n"; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/Special Permutation.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | if (n % 2 == 0) 34 | while (n > 0) 35 | cout << n-- << " "; 36 | else 37 | { 38 | int t = n; 39 | int g = n / 2 + 1; 40 | while (t > 0) 41 | { 42 | if (t != g) 43 | cout << t << " "; 44 | t--; 45 | } 46 | cout << g; 47 | } 48 | cout << "\n"; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/Minimal Square.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int a, b; 32 | cin >> a >> b; 33 | 34 | if (a == b) 35 | cout << (a + b) * (a + b); 36 | else 37 | { 38 | int minsq = min(a, b); 39 | int maxsq = max(a, b); 40 | if (minsq * 2 >= maxsq) 41 | cout << (minsq + minsq) * (minsq + minsq); 42 | else 43 | cout << maxsq * maxsq; 44 | } 45 | cout << "\n"; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 1000/Payment Without Change.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | ll BinarySearch(vector&arr, ll xx) 18 | { 19 | ll left = 0; 20 | ll right = arr.size() - 1; 21 | while (left <= right) 22 | { 23 | ll mid = (left + right) / 2; 24 | 25 | if (arr[mid] == xx) 26 | return mid; 27 | if (arr[mid] > xx) 28 | right = mid - 1; 29 | if (arr[mid] < xx) 30 | left = mid + 1; 31 | } 32 | return -1; 33 | } 34 | 35 | void SolveProblem() 36 | { 37 | ll a, b, n, S; 38 | cin >> a >> b >> n >> S; 39 | if (S - min(a, (S / n)) * n <= b) cout << "YES\n"; 40 | else cout << "NO\n"; 41 | } 42 | 43 | int main() 44 | { 45 | ios_base::sync_with_stdio(false); 46 | cin.tie(0); cout.tie(0); 47 | _TestCases_ 48 | SolveProblem(); 49 | 50 | return 0; 51 | } 52 | 53 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 54 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 55 | -------------------------------------------------------------------------------- /Level 800/Old-Even Increments.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | 18 | void SolveProblem() 19 | { 20 | ll n; cin >> n; 21 | vectora(n); 22 | bool evenIndexEven = false; 23 | bool evenIndexOdd = false; 24 | bool oddIndexEven = false; 25 | bool oddIndexOdd = false; 26 | 27 | for (ll i = 0; i < n; i++) 28 | { 29 | cin >> a[i]; 30 | if (i % 2 == 0) 31 | { 32 | if (a[i] % 2 == 0) evenIndexEven = true; 33 | else evenIndexOdd = true; 34 | } 35 | else 36 | { 37 | if (a[i] % 2 == 0) oddIndexEven = true; 38 | else oddIndexOdd = true; 39 | } 40 | } 41 | if (evenIndexEven == evenIndexOdd || oddIndexEven == oddIndexOdd) cout << "NO\n"; 42 | else cout << "YES\n"; 43 | } 44 | 45 | int main() 46 | { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); cout.tie(0); 49 | _TestCases_ 50 | SolveProblem(); 51 | 52 | return 0; 53 | } 54 | 55 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 56 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 57 | -------------------------------------------------------------------------------- /Level 800/Cards for Friends.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll w, h, n, res = 1; 32 | cin >> w >> h >> n; 33 | while (w % 2 == 0 || h % 2 == 0) 34 | { 35 | if (w % 2 == 0) 36 | { 37 | w /= 2; 38 | res *= 2; 39 | } 40 | else 41 | { 42 | h /= 2; 43 | res *= 2; 44 | } 45 | } 46 | if (res >= n) 47 | cout << "YES\n"; 48 | else 49 | cout << "NO\n"; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 800/Find The Array.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 4294967295 19 | #define MIN -4294967295 20 | #define ll long long 21 | #define loop(i) for(ll i = 0; i < n; i++) 22 | 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(0); cout.tie(0); 27 | 28 | int th; 29 | cin >> th; 30 | while (th--) 31 | { 32 | int s; 33 | cin >> s; 34 | int i = 1; 35 | int co = 0; 36 | while (s > 0) 37 | { 38 | s -= i; 39 | co++; 40 | i += 2; 41 | } 42 | cout << co << "\n"; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Level 800/Honest Coach.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -4294967295 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | vectora(n); 34 | 35 | for (int i = 0; i < n; i++) 36 | cin >> a[i]; 37 | sort(a.begin(), a.end()); 38 | 39 | int lc = MAX; 40 | for (int i = 0; i < n - 1; i++) 41 | { 42 | int minA = a[i + 1] - a[i]; 43 | if (minA < lc) 44 | lc = minA; 45 | } 46 | cout << lc; 47 | cout << "\n"; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Level 800/Vanya and Cubes.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 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 MAX 1000000000 22 | #define MIN -100000 23 | #define ll long long 24 | 25 | void SolveProblem() 26 | { 27 | int n; 28 | cin >> n; 29 | if (n == 1) 30 | cout << 1; 31 | else 32 | { 33 | int floor = 0; 34 | int res = 0; 35 | while (res <= n) 36 | { 37 | floor++; 38 | res += floor * (floor + 1) / 2; 39 | } 40 | cout << floor - 1; 41 | } 42 | } 43 | int main() 44 | { 45 | ios_base::sync_with_stdio(false); 46 | cin.tie(0); cout.tie(0); 47 | //ll th; 48 | //cin >> th; 49 | //while (th--) 50 | SolveProblem(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 800/Add Odd or Subtract Even.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll a, b; 32 | cin >> a >> b; 33 | if (a == b) 34 | cout << 0; 35 | else 36 | { 37 | if (a % 2 == b % 2) 38 | { 39 | if (a > b) 40 | cout << 1; 41 | else 42 | cout << 2; 43 | } 44 | else 45 | { 46 | if (a > b) 47 | cout << 2; 48 | else 49 | cout << 1; 50 | } 51 | } 52 | cout << "\n"; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 800/Collecting Coins.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(0); cout.tie(0); 27 | 28 | int th; 29 | cin >> th; 30 | while (th--) 31 | { 32 | int a, b, c, n; 33 | cin >> a >> b >> c >> n; 34 | int max3 = max(a, b); 35 | max3 = max(max3, c); 36 | if (a < max3) 37 | n -= (max3 - a); 38 | if (b < max3) 39 | n -= (max3 - b); 40 | if (c < max3) 41 | n -= (max3 - c); 42 | if (n >= 0 && n % 3 == 0) 43 | cout << "YES"; 44 | else 45 | cout << "NO"; 46 | cout << "\n"; 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 900/Vasya and Socks.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -4294967295 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int n, m; 28 | cin >> n >> m; 29 | int ans = n; 30 | if (n < m) 31 | cout << ans; 32 | else if (n == m) 33 | cout << ans + 1; 34 | else 35 | { 36 | int k = n / m; 37 | ans += k; 38 | int tt = n - k * m + k; 39 | if (tt >= m) 40 | { 41 | int ttt = tt; 42 | while (ttt >= m) 43 | { 44 | ans += ttt / m; 45 | ttt = ttt - m * (ttt / m) + ttt / m; 46 | } 47 | } 48 | cout << ans; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/Polycarp and Coins.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int CountNumbers(int k) 23 | { 24 | int c = 0; 25 | while (k != 0) 26 | { 27 | k /= 10; 28 | c++; 29 | } 30 | return c; 31 | } 32 | int main() 33 | { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); cout.tie(0); 36 | 37 | ll th; 38 | cin >> th; 39 | while (th--) 40 | { 41 | ll n; 42 | cin >> n; 43 | if (n % 3 == 0) 44 | cout << n / 3 << " " << n / 3; 45 | else if (n % 3 == 1) 46 | cout << n / 3 + 1 << " " << n / 3; 47 | else 48 | cout << n / 3 << " " << n / 3 + 1; 49 | cout << "\n"; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 1000/Move Brackets.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 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 MAX 1000000000 22 | #define MIN -100000 23 | #define ll long long 24 | 25 | void SolveProblem() 26 | { 27 | ll n; 28 | string s; 29 | cin >> n >> s; 30 | ll ans = 0, res = 0; 31 | for (ll i = 0; i < n; i++) 32 | { 33 | if (s[i] == '(') 34 | res++; 35 | else 36 | { 37 | res--; 38 | if (res < 0) 39 | { 40 | res = 0; 41 | ans++; 42 | } 43 | } 44 | } 45 | cout << ans << "\n"; 46 | } 47 | int main() 48 | { 49 | ios_base::sync_with_stdio(false); 50 | cin.tie(0); cout.tie(0); 51 | ll th; 52 | cin >> th; 53 | while (th--) 54 | SolveProblem(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Level 800/Boring Apartments.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int CountNumber(int k) 23 | { 24 | int c = 0; 25 | while (k != 0) 26 | { 27 | k /= 10; 28 | c++; 29 | } 30 | return c; 31 | } 32 | int Ok(int t) 33 | { 34 | if (t == 1) 35 | return 1; 36 | else if (t == 2) 37 | return 3; 38 | else if (t == 3) 39 | return 6; 40 | else 41 | return 10; 42 | } 43 | int main() 44 | { 45 | ios_base::sync_with_stdio(false); 46 | cin.tie(0); cout.tie(0); 47 | 48 | int th; 49 | cin >> th; 50 | while (th--) 51 | { 52 | int x; 53 | cin >> x; 54 | cout << (x % 10 - 1) * 10 + Ok(CountNumber(x)) << "\n"; 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Level 800/Mishka and Game.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | int n; 27 | cin >> n; 28 | vectora(2 * n); 29 | int c = 0; 30 | int m = 0; 31 | for (int i = 0; i < 2 * n; i++) 32 | { 33 | cin >> a[i]; 34 | if (i % 2 != 0) 35 | { 36 | if (a[i] > a[i - 1]) 37 | c++; 38 | else if (a[i] < a[i - 1]) 39 | m++; 40 | else 41 | { 42 | } 43 | } 44 | } 45 | if (c > m) 46 | cout << "Chris"; 47 | else if (c < m) 48 | cout << "Mishka"; 49 | else 50 | cout << "Friendship is magic!^^"; 51 | cout << "\n"; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Level 800/Phoenix and Balance.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll n; 32 | cin >> n; 33 | vectora; 34 | ll suma = 0; 35 | for (int i = n - 1; i > 0; i--) 36 | { 37 | a.push_back(pow(2, i)); 38 | suma += pow(2, i); 39 | } 40 | ll sumb = pow(2, n); 41 | for (int i = 1; i < n / 2; i++) 42 | { 43 | suma -= a[a.size() - 1]; 44 | sumb += a[a.size() - 1]; 45 | a.pop_back(); 46 | } 47 | cout << abs(suma - sumb); 48 | cout << "\n"; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/Brain's Photos.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | bool checkOK(char ch) 23 | { 24 | if (ch != 'W' && ch != 'B' && ch != 'G') 25 | return false; 26 | return true; 27 | 28 | } 29 | int main() 30 | { 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(0); cout.tie(0); 33 | 34 | int n, m; 35 | bool flag = true; 36 | cin >> n >> m; 37 | vector>a(n, vector(m)); 38 | for (int i = 0; i < n; i++) 39 | { 40 | for (int j = 0; j < m; j++) 41 | { 42 | cin >> a[i][j]; 43 | if (!checkOK(a[i][j])) 44 | flag = false; 45 | } 46 | } 47 | if (flag) 48 | cout << "#Black&White"; 49 | else 50 | cout << "#Color"; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 800/Colorful Stones (Simplified Edition).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | ll BinarySearch(vector&arr, ll xx) 18 | { 19 | ll left = 0; 20 | ll right = arr.size() - 1; 21 | while (left <= right) 22 | { 23 | ll mid = (left + right) / 2; 24 | 25 | if (arr[mid] == xx) 26 | return mid; 27 | if (arr[mid] > xx) 28 | right = mid - 1; 29 | if (arr[mid] < xx) 30 | left = mid + 1; 31 | } 32 | return -1; 33 | } 34 | 35 | void SolveProblem() 36 | { 37 | string s, t; 38 | cin >> s >> t; 39 | ll count = 0; 40 | 41 | for (ll i = 0; i < t.length(); i++) 42 | { 43 | if (t[i] == s[count]) count++; 44 | else continue; 45 | } 46 | cout << ++count; 47 | } 48 | 49 | int main() 50 | { 51 | ios_base::sync_with_stdio(false); 52 | cin.tie(0); cout.tie(0); 53 | //_TestCases_ 54 | SolveProblem(); 55 | 56 | return 0; 57 | } 58 | 59 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 60 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 61 | -------------------------------------------------------------------------------- /Level 800/Gennady and a Card Game.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | string s, ss; 30 | getline(cin, s); 31 | getline(cin, ss); 32 | bool flag = false; 33 | for (ll i = 0; i < ss.length(); i++) 34 | { 35 | if (ss[i] == s[0] || ss[i] == s[1]) 36 | { 37 | flag = true; 38 | break; 39 | } 40 | } 41 | if (flag) 42 | cout << "YES"; 43 | else 44 | cout << "NO"; 45 | } 46 | int main() 47 | { 48 | ios_base::sync_with_stdio(false); 49 | cin.tie(0); cout.tie(0); 50 | /*ll th; 51 | cin >> th; 52 | while (th--)*/ 53 | SolveProblem(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 800/Spy Detected!.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | vectora(n); 34 | for (int i = 0; i < n; i++) 35 | cin >> a[i]; 36 | if (a[0] != a[1] && a[0] != a[2]) 37 | cout << 1; 38 | else if (a[n - 1] != a[n - 2] && a[n - 1] != a[n - 3]) 39 | cout << n; 40 | else 41 | { 42 | int vti = -1; 43 | for (int i = 1; i < n - 1; i++) 44 | if (a[i] != a[i - 1] && a[i] != a[i + 1]) 45 | vti = i; 46 | cout << vti + 1; 47 | } 48 | cout << "\n"; 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/I Wanna Be the Guy.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | int n; 23 | cin >> n; 24 | int pX, pY; 25 | cin >> pX; 26 | vectora1(pX); 27 | for (int i = 0; i < pX; i++) 28 | cin >> a1[i]; 29 | 30 | cin >> pY; 31 | vectora2(pY); 32 | for (int i = 0; i < pY; i++) 33 | cin >> a2[i]; 34 | vectorres(n + 1, false); 35 | res[0] = true; 36 | for (int i = 0; i < pX; i++) 37 | res[a1[i]] = true; 38 | for (int i = 0; i < pY; i++) 39 | res[a2[i]] = true; 40 | bool flag = true; 41 | for (int i = 0; i < res.size(); i++) 42 | if (res[i] == false) 43 | flag = false; 44 | if (flag == true) 45 | cout << "I become the guy."; 46 | else 47 | cout << "Oh, my keyboard!"; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 1200/BerSU Ball.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int n, m; 28 | cin >> n; 29 | vectora(n); 30 | for (int i = 0; i < n; i++) 31 | cin >> a[i]; 32 | cin >> m; 33 | vectorb(m); 34 | for (int i = 0; i < m; i++) 35 | cin >> b[i]; 36 | sort(a.begin(), a.end()); 37 | sort(b.begin(), b.end()); 38 | 39 | int res = 0; 40 | 41 | for (int i = 0; i < n; i++) 42 | { 43 | for (int j = 0; j < m; j++) 44 | { 45 | if (abs(a[i] - b[j]) <= 1) 46 | { 47 | res++; 48 | a[i] = MIN; 49 | b[j] = MAX; 50 | } 51 | } 52 | } 53 | cout << res; 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Level 800/Ordinary Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | //typedef long long ll; 11 | 12 | int CountNumbers(int t) 13 | { 14 | int num = t; 15 | int co = 0; 16 | while (num != 0) 17 | { 18 | num /= 10; 19 | co++; 20 | } 21 | return co; 22 | } 23 | int FirstNum(int t) 24 | { 25 | int co = CountNumbers(t); 26 | int res = 1; 27 | for (int i = 2; i <= co; i++) 28 | res *= 10; 29 | return t / res; 30 | } 31 | int main() 32 | { 33 | ios_base::sync_with_stdio(false); 34 | cin.tie(0); cout.tie(0); 35 | 36 | int th; 37 | cin >> th; 38 | while (th--) 39 | { 40 | int n; 41 | cin >> n; 42 | if (CountNumbers(n) == 10) 43 | cout << 81; 44 | else if (n / 10 == 0) 45 | cout << n; 46 | else 47 | { 48 | int ans = 0; 49 | int fNum = FirstNum(n); 50 | vectora(10); 51 | a[0] = 0; 52 | for (int i = 1; i < 10; i++) 53 | a[i] = a[i - 1] * 10 + 1; 54 | int count_num = CountNumbers(n); 55 | ans = ans + (count_num - 1) * 9; 56 | if (n >= a[count_num] * fNum) 57 | ans += fNum; 58 | else 59 | ans = ans + fNum - 1; 60 | cout << ans; 61 | } 62 | cout << "\n"; 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Level 800/Replacing Elements.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n, d; 32 | cin >> n >> d; 33 | vectora(n); 34 | int count = 0; 35 | for (int i = 0; i < n; i++) 36 | { 37 | cin >> a[i]; 38 | if (a[i] <= d) 39 | count++; 40 | } 41 | if (count <= 1) 42 | cout << "NO"; 43 | else if (count == n) 44 | cout << "YES"; 45 | else 46 | { 47 | sort(a.begin(), a.end()); 48 | if (a[0] + a[1] <= d) 49 | cout << "YES"; 50 | else 51 | cout << "NO"; 52 | } 53 | cout << "\n"; 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Level 1000/Olesya and Rodion.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | int n; 29 | string t; 30 | cin >> n >> t; 31 | vectora; 32 | 33 | if (t == "10") 34 | { 35 | if (n == 1) 36 | a.push_back("-1"); 37 | else 38 | { 39 | a.resize(n, "0"); 40 | a[0] = "1"; 41 | } 42 | } 43 | else 44 | a.resize(n, t); 45 | for (int i = 0; i < a.size(); i++) 46 | cout << a[i]; 47 | cout << "\n"; 48 | } 49 | int main() 50 | { 51 | ios_base::sync_with_stdio(false); 52 | cin.tie(0); cout.tie(0); 53 | //ll th; 54 | //cin >> th; 55 | //while (th--) 56 | SolveProblem(); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Level 1100/Ilya and Queries.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | string s; 29 | getline(cin, s); 30 | ll n, k = 1; 31 | cin >> n; 32 | vectora; 33 | a.push_back(1); 34 | for (ll i = 1; i < s.size(); i++) 35 | { 36 | if (s[i] == s[i - 1]) 37 | k++; 38 | a.push_back(k); 39 | } 40 | 41 | while (n--) 42 | { 43 | ll l, r; 44 | cin >> l >> r; 45 | cout << a[r - 1] - a[l - 1] << "\n"; 46 | } 47 | } 48 | int main() 49 | { 50 | ios_base::sync_with_stdio(false); 51 | cin.tie(0); cout.tie(0); 52 | /*ll th; 53 | cin >> th; 54 | while (th--)*/ 55 | SolveProblem(); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Level 800/Do Not Be Distracted!.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | int th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | string s; 34 | cin >> s; 35 | vectorstr(MAX, -1); 36 | bool flag = true; 37 | for (int i = 0; i < n; i++) 38 | { 39 | if (str[s[i] - 65] == -1) 40 | str[s[i] - 65] = i; 41 | else 42 | { 43 | if ((i - str[s[i] - 65]) != 1) 44 | flag = false; 45 | else 46 | str[s[i] - 65] = i; 47 | } 48 | } 49 | if (flag) 50 | cout << "YES"; 51 | else 52 | cout << "NO"; 53 | cout << "\n"; 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Level 800/Medium Number.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | 10 | #include 11 | //#include 12 | //#include 13 | 14 | using namespace std; 15 | 16 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 17 | #define db double 18 | #define ld long double 19 | #define ll long long 20 | #define i64 __int64 // == ll 21 | #define ull unsigned long long 22 | #define ui64 unsigned __int64 // == unsigned ll 23 | #define pq priority_queue 24 | #define sortU(v) sort(v.begin(), v.end()) 25 | #define sortD(v) sort(v.rbegin(), v.rend()) 26 | #define pll pair 27 | #define psl pair 28 | #define MOD 1e9 + 7 29 | 30 | 31 | void solve() 32 | { 33 | vectora(3); 34 | cin >> a[0] >> a[1] >> a[2]; 35 | sortU(a); 36 | cout << a[1] << "\n"; 37 | } 38 | 39 | int main() 40 | { 41 | ios_base::sync_with_stdio(false); 42 | cin.tie(0); cout.tie(0); 43 | _TestCases_ 44 | solve(); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Level 900/Construct the String.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | #define MAX 100000 20 | #define MIN -100000 21 | #define ll long long 22 | 23 | void SolveProblem() 24 | { 25 | int n, a, b; 26 | cin >> n >> a >> b; 27 | vectorvec(n); 28 | int co = 1; 29 | char f = 'a'; 30 | for (int i = 0; i < n; i++) 31 | { 32 | if (co < b) 33 | { 34 | vec[i] = f; 35 | f++; 36 | co++; 37 | } 38 | else 39 | { 40 | vec[i] = f; 41 | f = 'a'; 42 | co = 1; 43 | } 44 | } 45 | for (int i = 0; i < n; i++) 46 | cout << vec[i]; 47 | cout << "\n"; 48 | } 49 | int main() 50 | { 51 | ios_base::sync_with_stdio(false); 52 | cin.tie(0); cout.tie(0); 53 | 54 | int th; 55 | cin >> th; 56 | while (th--) 57 | SolveProblem(); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Level 800/Fair Division.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | int n; 32 | cin >> n; 33 | vectora(n); 34 | vectorone; 35 | vectoroneone; 36 | 37 | int cOne = 0, cTwo = 0, sum = 0; 38 | for (int i = 0; i < n; i++) 39 | { 40 | cin >> a[i]; 41 | if (a[i] == 1) 42 | cOne++; 43 | else 44 | cTwo++; 45 | sum += a[i]; 46 | } 47 | if (cOne == 0 && cTwo % 2 != 0) 48 | cout << "NO"; 49 | else if (cOne % 2 != 0) 50 | cout << "NO"; 51 | else 52 | cout << "YES"; 53 | cout << "\n"; 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Level 1100/Fancy Fence.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | int BinarySearch(vector& arr, int xx) 22 | { 23 | int left = 0; 24 | int right = arr.size() - 1; 25 | while (left <= right) 26 | { 27 | int mid = (left + right) / 2; 28 | 29 | if (arr[mid] == xx) 30 | return mid; 31 | if (arr[mid] > xx) 32 | right = mid - 1; 33 | if (arr[mid] < xx) 34 | left = mid + 1; 35 | } 36 | return -1; 37 | } 38 | int main() 39 | { 40 | ios_base::sync_with_stdio(false); 41 | cin.tie(0); cout.tie(0); 42 | 43 | int th; 44 | cin >> th; 45 | while (th--) 46 | { 47 | int a; 48 | cin >> a; 49 | if (360 % (180 - a) == 0) 50 | cout << "YES\n"; 51 | else 52 | cout << "NO\n"; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 1200/Fall Down.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | void SolveProblem() 18 | { 19 | ll n, m; cin >> n >> m; 20 | vector>a(n, vector(m)); 21 | for (ll i = 0; i < n; i++) 22 | for (ll j = 0; j < m; j++) 23 | cin >> a[i][j]; 24 | for (ll loop = 0; loop < n; loop++) 25 | { 26 | for (ll j = 0; j < m; j++) 27 | { 28 | for (ll i = n - 1; i >= 0; i--) 29 | { 30 | if (i != n - 1 && a[i][j] == '*' && a[i + 1][j] == '.') 31 | swap(a[i][j], a[i + 1][j]); 32 | } 33 | } 34 | } 35 | 36 | for (ll i = 0; i < n; i++) 37 | { 38 | for (ll j = 0; j < m; j++) 39 | { 40 | cout << a[i][j]; 41 | } 42 | cout << "\n"; 43 | } 44 | } 45 | 46 | int main() 47 | { 48 | ios_base::sync_with_stdio(false); 49 | cin.tie(0); cout.tie(0); 50 | _TestCases_ 51 | SolveProblem(); 52 | 53 | return 0; 54 | } 55 | 56 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 57 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 58 | -------------------------------------------------------------------------------- /Level 800/Presents.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | int n; 26 | cin >> n; 27 | vectora(n); 28 | vectorb; 29 | for (int i = 0; i < n; i++) 30 | { 31 | cin >> a[i]; 32 | b.push_back(i + 1); 33 | } 34 | ll min_index; 35 | for (ll i = 0; i < a.size() - 1; i++) 36 | { 37 | min_index = i; 38 | for (ll j = i + 1; j < a.size(); j++) 39 | if (a[min_index] > a[j]) 40 | min_index = j; 41 | swap(a[min_index], a[i]); 42 | swap(b[min_index], b[i]); 43 | } 44 | for (int i = 0; i < n; i++) 45 | cout << b[i] << " "; 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Level 900/Lineland Mail.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(0); cout.tie(0); 14 | 15 | ll n; 16 | cin >> n; 17 | vectora(n); 18 | for (ll i = 0; i < n; i++) 19 | cin >> a[i]; 20 | 21 | if (n == 2) 22 | { 23 | ll kq = abs(a[1] - a[0]); 24 | cout << kq << " " << kq << "\n" << kq << " " << kq; 25 | } 26 | else 27 | { 28 | //Thanh pho dau tien 29 | ll kq1 = a[1] - a[0]; 30 | ll kq2 = a[n - 1] - a[0]; 31 | if (kq1 < kq2) 32 | cout << kq1 << " " << kq2 << "\n"; 33 | else 34 | cout << kq2 << " " << kq1 << "\n"; 35 | //1 -> n-2 thanh pho giua 36 | for (ll i = 1; i < n - 1; i++) 37 | { 38 | vectorkq(4); 39 | kq[0] = a[i] - a[i - 1]; 40 | kq[1] = a[i + 1] - a[i]; 41 | kq[2] = a[i] - a[0]; 42 | kq[3] = a[n - 1] - a[i]; 43 | sort(kq.begin(), kq.end()); 44 | cout << kq[0] << " " << kq[3] << "\n"; 45 | } 46 | //Thanh pho cuoi cung 47 | ll kq_cuoi1 = a[n - 1] - a[0]; 48 | ll kq_cuoi2 = a[n - 1] - a[n - 2]; 49 | if (kq_cuoi1 < kq_cuoi2) 50 | cout << kq_cuoi1 << " " << kq_cuoi2; 51 | else 52 | cout << kq_cuoi2 << " " << kq_cuoi1; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 800/Arrival of the General.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | 20 | int main() 21 | { 22 | ios_base::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | 25 | int n; 26 | cin >> n; 27 | vectora(n); 28 | 29 | int min = 101; 30 | int max = 0; 31 | int vt_min = -1; 32 | int vt_max = -1; 33 | for (int i = 0; i < n; i++) 34 | { 35 | cin >> a[i]; 36 | if (a[i] > max) 37 | { 38 | max = a[i]; 39 | vt_max = i; 40 | } 41 | if (a[i] <= min) 42 | { 43 | min = a[i]; 44 | vt_min = i; 45 | } 46 | } 47 | if (vt_max < vt_min) 48 | cout << vt_max + n - 1 - vt_min; 49 | else 50 | { 51 | int sw = vt_max - vt_min; 52 | vt_max = vt_min; 53 | vt_min = vt_max + 1; 54 | cout << vt_max + n - 1 - vt_min + sw; 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Level 1200/Cheap Travel.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | 24 | float n, m, a, b; 25 | cin >> n >> m >> a >> b; 26 | 27 | if (m == 1) 28 | { 29 | if (n * a > n * b) 30 | cout << (int)n * (int)b; 31 | else 32 | cout << (int)n * (int)a; 33 | } 34 | else if ((b / m) >= a) 35 | cout << (int)n * (int)a; 36 | else 37 | { 38 | int ans = 0; 39 | int t = n / m; 40 | ans = t * (int)b; 41 | int tt = n - t * m; 42 | if (tt * a > b) 43 | ans += b; 44 | else 45 | ans += tt * a; 46 | cout << ans; 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Level 800/Ezzat and Two Subsequences.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | using namespace std; 22 | 23 | #define MAX 1000000000 24 | #define MIN -1000000000 25 | #define ll long long 26 | 27 | void SolveProblem() 28 | { 29 | ll n; 30 | cin >> n; 31 | vectora(n); 32 | ll lc = MIN; 33 | ll sum = 0; 34 | for (ll i = 0; i < n; i++) 35 | { 36 | cin >> a[i]; 37 | sum += a[i]; 38 | if (a[i] > lc) 39 | lc = a[i]; 40 | } 41 | sum -= lc; 42 | double ave = (double)sum / (n - 1); 43 | double res = (double)lc + ave; 44 | cout << fixed << setprecision(9) << res << "\n"; 45 | } 46 | int main() 47 | { 48 | ios_base::sync_with_stdio(false); 49 | cin.tie(0); cout.tie(0); 50 | ll th; 51 | cin >> th; 52 | while (th--) 53 | SolveProblem(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 800/Favorite Sequence.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll n; 30 | cin >> n; 31 | vectora(n); 32 | vectorb(n); 33 | ll first = 0; 34 | ll last = n - 1; 35 | for (ll i = 0; i < n; i++) 36 | cin >> a[i]; 37 | for (ll i = 0; i < n; i++) 38 | { 39 | if (i % 2 == 0) 40 | b[i] = a[first++]; 41 | else 42 | b[i] = a[last--]; 43 | } 44 | for (ll i = 0; i < n; i++) 45 | cout << b[i] << " "; 46 | cout << "\n"; 47 | } 48 | int main() 49 | { 50 | ios_base::sync_with_stdio(false); 51 | cin.tie(0); cout.tie(0); 52 | ll th; 53 | cin >> th; 54 | while (th--) 55 | SolveProblem(); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Level 800/Ichihime and Triangle.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 25 | #define MAX 1000000000 26 | #define MIN -1 27 | 28 | #define db double 29 | #define ld long double 30 | #define ll long long 31 | #define i64 __int64 // == long long 32 | 33 | #define ull unsigned long long 34 | #define ui64 unsigned __int64 // == unsigned long long 35 | 36 | 37 | void SolveProblem() 38 | { 39 | ll a, b, c, d; 40 | cin >> a >> b >> c >> d; 41 | cout << b << " " << c << " " << c << "\n"; 42 | } 43 | int main() 44 | { 45 | ios_base::sync_with_stdio(false); 46 | cin.tie(0); cout.tie(0); 47 | _TestCases_ 48 | SolveProblem(); 49 | return 0; 50 | } 51 |   52 | -------------------------------------------------------------------------------- /Level 1200/Flipping Game.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | int n; 29 | cin >> n; 30 | int sum = 0, max = 0, one = 0, a; 31 | for (int i = 0; i < n; i++) 32 | { 33 | cin >> a; 34 | if (a == 0) 35 | sum++; 36 | else 37 | { 38 | one++; 39 | sum--; 40 | } 41 | if (sum < 0) 42 | sum = 0; 43 | if (sum > max) 44 | max = sum; 45 | } 46 | 47 | if (one == n) 48 | cout << n - 1; 49 | else 50 | cout << max + one; 51 | } 52 | int main() 53 | { 54 | ios_base::sync_with_stdio(false); 55 | cin.tie(0); cout.tie(0); 56 | //ll th; 57 | //cin >> th; 58 | //while (th--) 59 | SolveProblem(); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /Level 1000/Raising Bacteria.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 26 19 | #define MIN -1 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll n; 28 | cin >> n; 29 | int vti = -1; 30 | vectorW; 31 | for (int i = 0; i < 30; i++) 32 | { 33 | W.push_back(pow(2, i)); 34 | if (pow(2, i) == n) 35 | { 36 | cout << 1; 37 | return 0; 38 | } 39 | else if (pow(2, i) < n) 40 | vti = i; 41 | } 42 | int count = 0; 43 | while (n > 0) 44 | { 45 | if (n > W[vti]) 46 | { 47 | n -= W[vti]; 48 | count++; 49 | vti--; 50 | } 51 | else if (n == W[vti]) 52 | { 53 | count += 1; 54 | cout << count; 55 | return 0; 56 | } 57 | else 58 | { 59 | vti--; 60 | } 61 | } 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /Level 800/Design Tutorial: Learn from Math.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | typedef long long ll; 19 | void Prime(vector& a, ll num) 20 | { 21 | a.resize(num + 1, true); 22 | a[0] = false; 23 | a[1] = false; 24 | 25 | for (ll i = 0; i <= sqrt(num); i++) 26 | { 27 | if (a[i]) 28 | { 29 | for (ll j = i * i; j <= num; j += i) 30 | { 31 | a[j] = false; 32 | } 33 | } 34 | } 35 | } 36 | int main() 37 | { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(0); cout.tie(0); 40 | 41 | ll n; 42 | cin >> n; 43 | vectorsieve; 44 | Prime(sieve, n); 45 | for (ll i = 4; i < sieve.size(); i++) 46 | { 47 | if (!sieve[i]) 48 | { 49 | ll j = n - i; 50 | if (!sieve[j]) 51 | { 52 | cout << i << " " << j; 53 | i = sieve.size(); 54 | } 55 | } 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Level 800/YES or YES?.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | 10 | #include 11 | //#include 12 | //#include 13 | 14 | using namespace std; 15 | 16 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 17 | #define db double 18 | #define ld long double 19 | #define ll long long 20 | #define i64 __int64 // == ll 21 | #define ull unsigned long long 22 | #define ui64 unsigned __int64 // == unsigned ll 23 | #define pq priority_queue 24 | #define sortU(v) sort(v.begin(), v.end()) 25 | #define sortD(v) sort(v.rbegin(), v.rend()) 26 | #define pll pair 27 | #define psl pair 28 | #define MOD 1e9 + 7 29 | 30 | 31 | void solve() 32 | { 33 | string s; cin >> s; 34 | transform(s.begin(), s.end(), s.begin(), ::tolower); 35 | if (s == "yes") cout << "YES\n"; 36 | else cout << "NO\n"; 37 | } 38 | 39 | int main() 40 | { 41 | ios_base::sync_with_stdio(false); 42 | cin.tie(0); cout.tie(0); 43 | _TestCases_ 44 | solve(); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Level 1300/Reverse String.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | string strCopy(string s) 23 | { 24 | string ss = ""; 25 | for (int i = s.length() - 2; i >= 0; i--) 26 | ss += s[i]; 27 | return ss; 28 | } 29 | 30 | int main() 31 | { 32 | ios_base::sync_with_stdio(false); 33 | cin.tie(0); cout.tie(0); 34 | 35 | ll th; 36 | cin >> th; 37 | while (th--) 38 | { 39 | string s, t, ss; 40 | cin >> s >> t; 41 | string ans = ""; 42 | bool flag = false; 43 | for (int i = 0; i < s.length(); ++i) 44 | { 45 | ans += s[i]; 46 | string str = ans + strCopy(ans); 47 | if (str.find(t) != s.npos) 48 | flag = true; 49 | } 50 | if (flag) 51 | cout << "YES"; 52 | else 53 | cout << "NO"; 54 | cout << "\n"; 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Level 800/Vus the Cossack and a Contest.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 25 | #define MAX 1000000000 26 | #define MIN -1 27 | 28 | #define db double 29 | #define ld long double 30 | #define ll long long 31 | #define i64 __int64 // == ll 32 | 33 | #define ull unsigned long long 34 | #define ui64 unsigned __int64 // == unsigned ll 35 | 36 | #define pq priority_queue 37 | 38 | void SolveProblem() 39 | { 40 | ll n, m, k; 41 | cin >> n >> m >> k; 42 | if (m < n || k < n) cout << "NO"; 43 | else cout << "YES"; 44 | } 45 | int main() 46 | { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); cout.tie(0); 49 | //_TestCases_ 50 | SolveProblem(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Level 800/Codeforces Checking.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | 10 | #include 11 | //#include 12 | //#include 13 | 14 | using namespace std; 15 | 16 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 17 | #define db double 18 | #define ld long double 19 | #define ll long long 20 | #define i64 __int64 // == ll 21 | #define ull unsigned long long 22 | #define ui64 unsigned __int64 // == unsigned ll 23 | #define pq priority_queue 24 | #define sortU(v) sort(v.begin(), v.end()) 25 | #define sortD(v) sort(v.rbegin(), v.rend()) 26 | #define pll pair 27 | #define psl pair 28 | #define MOD 1e9 + 7 29 | 30 | 31 | void solve() 32 | { 33 | char cha; cin >> cha; 34 | string s = "codeforces"; 35 | if (s.find(cha) != std::string::npos) 36 | cout << "YES\n"; 37 | else cout << "NO\n"; 38 | } 39 | 40 | int main() 41 | { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); cout.tie(0); 44 | _TestCases_ 45 | solve(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Level 800/LCM Problem.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 25 | #define MAX 1000000000 26 | #define MIN -1 27 | 28 | #define db double 29 | #define ld long double 30 | #define ll long long 31 | #define i64 __int64 // == long long 32 | 33 | #define ull unsigned long long 34 | #define ui64 unsigned __int64 // == unsigned long long 35 | 36 | 37 | void SolveProblem() 38 | { 39 | ll l, r; 40 | cin >> l >> r; 41 | if (l * 2 > r) 42 | cout << -1 << " " << -1; 43 | else 44 | cout << l << " " << l * 2; 45 | cout << "\n"; 46 | } 47 | int main() 48 | { 49 | ios_base::sync_with_stdio(false); 50 | cin.tie(0); cout.tie(0); 51 | _TestCases_ 52 | SolveProblem(); 53 | return 0; 54 | } 55 |   56 | -------------------------------------------------------------------------------- /Level 1000/New Year Candles.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100 19 | #define MIN -1 20 | #define ll long long 21 | 22 | ll BinarySearch(vector& arr, ll xx) 23 | { 24 | ll left = 0; 25 | ll right = arr.size() - 1; 26 | while (left <= right) 27 | { 28 | ll mid = (left + right) / 2; 29 | 30 | if (arr[mid] <= xx) 31 | return mid; 32 | if (arr[mid] > xx) 33 | right = mid - 1; 34 | } 35 | return -1; 36 | } 37 | int main() 38 | { 39 | ios_base::sync_with_stdio(false); 40 | cin.tie(0); cout.tie(0); 41 | 42 | int a, b; 43 | cin >> a >> b; 44 | 45 | int ans = a; 46 | if (a < b) 47 | cout << ans; 48 | else if (a == b) 49 | cout << ans + 1; 50 | else 51 | { 52 | int res = a; 53 | while (res >= b) 54 | { 55 | res = res - b; 56 | res++; 57 | ans++; 58 | } 59 | cout << ans; 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Level 800/Borze.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | void SolveProblem() 27 | { 28 | string s; 29 | getline(cin, s); 30 | ll i = 0; 31 | stackst; 32 | while (i < s.size()) 33 | { 34 | if (s[i] == '.') 35 | { 36 | if (st.empty()) 37 | cout << "0"; 38 | else 39 | { 40 | cout << "1"; 41 | st.pop(); 42 | } 43 | } 44 | else 45 | { 46 | if (st.empty()) 47 | st.push(s[i]); 48 | else 49 | { 50 | cout << "2"; 51 | st.pop(); 52 | } 53 | } 54 | i++; 55 | } 56 | } 57 | int main() 58 | { 59 | ios_base::sync_with_stdio(false); 60 | cin.tie(0); cout.tie(0); 61 | /*ll th; 62 | cin >> th; 63 | while (th--)*/ 64 | SolveProblem(); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Level 1100/Sum of Odd Integers.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 25 | #define MAX 101 26 | #define MIN -1 27 | 28 | #define db double 29 | #define ld long double 30 | #define ll long long 31 | #define i64 __int64 // == ll 32 | 33 | #define ull unsigned long long 34 | #define ui64 unsigned __int64 // == unsigned ll 35 | 36 | #define pq priority_queue 37 | 38 | void SolveProblem() 39 | { 40 | ll n, k; 41 | cin >> n >> k; 42 | if (n % 2 != k % 2 || k * k > n) 43 | cout << "NO"; 44 | else 45 | cout << "YES"; 46 | cout << "\n"; 47 | } 48 | int main() 49 | { 50 | ios_base::sync_with_stdio(false); 51 | cin.tie(0); cout.tie(0); 52 | _TestCases_ 53 | SolveProblem(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Level 800/Minority.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | ll BinarySearch(vector&arr, ll xx) 18 | { 19 | ll left = 0; 20 | ll right = arr.size() - 1; 21 | while (left <= right) 22 | { 23 | ll mid = (left + right) / 2; 24 | 25 | if (arr[mid] == xx) 26 | return mid; 27 | if (arr[mid] > xx) 28 | right = mid - 1; 29 | if (arr[mid] < xx) 30 | left = mid + 1; 31 | } 32 | return -1; 33 | } 34 | 35 | void SolveProblem() 36 | { 37 | string s; cin >> s; 38 | ll one = 0; 39 | ll zero = 0; 40 | for (ll i = 0; i < s.length(); i++) 41 | { 42 | if (s[i] == '0') zero++; 43 | else one++; 44 | } 45 | if (s.size() <= 2) cout << 0 << "\n"; 46 | else 47 | { 48 | if (zero != one) cout << min(zero, one) << "\n"; 49 | else cout << --one << "\n"; 50 | } 51 | } 52 | 53 | int main() 54 | { 55 | ios_base::sync_with_stdio(false); 56 | cin.tie(0); cout.tie(0); 57 | _TestCases_ 58 | SolveProblem(); 59 | 60 | return 0; 61 | } 62 | 63 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 64 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 65 | -------------------------------------------------------------------------------- /Level 900/Filling Diamonds.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 25 | #define MAX 1000000007 26 | #define MIN -1 27 | #define db double 28 | #define ld long double 29 | #define ll long long 30 | #define i64 __int64 // == ll 31 | #define ull unsigned long long 32 | #define ui64 unsigned __int64 // == unsigned ll 33 | #define pq priority_queue 34 | #define sort(v) sort(v.begin(), v.end()) 35 | #define _sort(v) sort(v.rbegin(), v.rend()) 36 | #define pll pair 37 | 38 | void SolveProblem() 39 | { 40 | ll n; 41 | cin >> n; 42 | cout << n << "\n"; 43 | } 44 | int main() 45 | { 46 | ios_base::sync_with_stdio(false); 47 | cin.tie(0); cout.tie(0); 48 | _TestCases_ 49 | SolveProblem(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 1100/Laptops.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | #define MAX 1000000000 23 | #define MIN -100000 24 | #define ll long long 25 | 26 | 27 | void SolveProblem() 28 | { 29 | ll n; 30 | cin >> n; 31 | vectora(2, 0); 32 | bool flag = false; 33 | for (ll i = 0; i < n; i++) 34 | { 35 | ll num1, num2; 36 | cin >> num1 >> num2; 37 | ll num = num1 - num2; 38 | if (num < 0) 39 | a[0] = 1; 40 | else if (num > 0) 41 | a[1] = 1; 42 | if (a[0] != 0 && a[1] != 0) 43 | { 44 | flag = true; 45 | break; 46 | } 47 | } 48 | if (flag) 49 | cout << "Happy Alex"; 50 | else 51 | cout << "Poor Alex"; 52 | } 53 | int main() 54 | { 55 | ios_base::sync_with_stdio(false); 56 | cin.tie(0); cout.tie(0); 57 | /*ll th; 58 | cin >> th; 59 | while (th--)*/ 60 | SolveProblem(); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Level 1300/Coin Rows.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #define MAX 100000 19 | #define MIN -100000 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); cout.tie(0); 26 | 27 | ll th; 28 | cin >> th; 29 | while (th--) 30 | { 31 | ll m; 32 | cin >> m; 33 | vectora(m); 34 | vectorb(m); 35 | vectorres; 36 | 37 | ll sumt = 0; 38 | ll sumd = 0; 39 | for (ll i = 0; i < m; i++) 40 | { 41 | cin >> a[i]; 42 | if (i != 0) 43 | sumt += a[i]; 44 | } 45 | for (ll i = 0; i < m; i++) 46 | cin >> b[i]; 47 | res.push_back(max(sumt, sumd)); 48 | for (ll i = 1; i < m; i++) 49 | { 50 | sumt -= a[i]; 51 | sumd += b[i - 1]; 52 | res.push_back(max(sumt, sumd)); 53 | } 54 | sort(res.begin(), res.end()); 55 | cout << res[0]; 56 | cout << "\n"; 57 | } 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Level 1000/Bogosort.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | 10 | #include 11 | //#include 12 | //#include 13 | 14 | using namespace std; 15 | 16 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 17 | #define db double 18 | #define ld long double 19 | #define ll long long 20 | #define i64 __int64 // == ll 21 | #define ull unsigned long long 22 | #define ui64 unsigned __int64 // == unsigned ll 23 | #define pq priority_queue 24 | #define sortU(v) sort(v.begin(), v.end()) 25 | #define sortD(v) sort(v.rbegin(), v.rend()) 26 | #define pll pair 27 | #define psl pair 28 | #define MOD 1e9 + 7 29 | 30 | void solve() 31 | { 32 | ll n; cin >> n; 33 | vectora(n); 34 | for (ll i = 0; i < n; i++) 35 | cin >> a[i]; 36 | 37 | sortD(a); 38 | for (ll i = 0; i < n; i++) 39 | cout << a[i] << " "; 40 | cout << "\n"; 41 | } 42 | 43 | int main() 44 | { 45 | ios_base::sync_with_stdio(false); 46 | cin.tie(0); cout.tie(0); 47 | _TestCases_ 48 | solve(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Level 800/Average Height.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 6 | #define db double 7 | #define ld long double 8 | #define ll long long 9 | #define i64 __int64 // == ll 10 | #define ull unsigned long long 11 | #define ui64 unsigned __int64 // == unsigned ll 12 | #define pq priority_queue 13 | #define sortU(v) sort(v.begin(), v.end()) 14 | #define sortD(v) sort(v.rbegin(), v.rend()) 15 | #define pll pair 16 | 17 | ll BinarySearch(vector&arr, ll xx) 18 | { 19 | ll left = 0; 20 | ll right = arr.size() - 1; 21 | while (left <= right) 22 | { 23 | ll mid = (left + right) / 2; 24 | 25 | if (arr[mid] == xx) 26 | return mid; 27 | if (arr[mid] > xx) 28 | right = mid - 1; 29 | if (arr[mid] < xx) 30 | left = mid + 1; 31 | } 32 | return -1; 33 | } 34 | 35 | void SolveProblem() 36 | { 37 | ll n; cin >> n; 38 | vectora(n); 39 | dequed; 40 | for (ll i = 0; i < n; i++) 41 | { 42 | cin >> a[i]; 43 | if (a[i] % 2) d.push_back(a[i]); 44 | else d.push_front(a[i]); 45 | } 46 | for (ll i = d.size(); i > 0; i--) 47 | { 48 | cout << d.back() << " "; 49 | d.pop_back(); 50 | } 51 | cout << "\n"; 52 | } 53 | 54 | int main() 55 | { 56 | ios_base::sync_with_stdio(false); 57 | cin.tie(0); cout.tie(0); 58 | _TestCases_ 59 | SolveProblem(); 60 | 61 | return 0; 62 | } 63 | 64 | // Shortcut key for comment in Visual Studio 2019: Ctrl + K + C 65 | // Shortcut key for uncomment in Visual Studio 2019: Ctrl + K + U 66 | -------------------------------------------------------------------------------- /Level 800/Team Composition: Programmers and Mathematicians.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------* 2 | | User: Huynh Viet Tuan Kiet | 3 | | Degree: Student - Formal University | 4 | | Study Computer Science at the University of Information Technology | 5 | | Country: Viet Nam | 6 | | City: Ho Chi Minh | 7 | | Organization: VNUHCM - UIT - University of Information Technology | 8 | *-------------------------------------------------------------------------*/ 9 | 10 | #include 11 | //#include 12 | //#include 13 | 14 | using namespace std; 15 | 16 | #define _TestCases_ ll tcs; cin >> tcs; while (tcs--) 17 | #define db double 18 | #define ld long double 19 | #define ll long long 20 | #define i64 __int64 // == ll 21 | #define ull unsigned long long 22 | #define ui64 unsigned __int64 // == unsigned ll 23 | #define pq priority_queue 24 | #define sortU(v) sort(v.begin(), v.end()) 25 | #define sortD(v) sort(v.rbegin(), v.rend()) 26 | #define pll pair 27 | #define psl pair 28 | #define MOD 1e9 + 7 29 | 30 | 31 | void solve() 32 | { 33 | ll a, b; cin >> a >> b; 34 | if (a > b) swap(a, b); 35 | 36 | if (3 * a < b) 37 | cout << a << "\n"; 38 | else 39 | cout << (a + b) / 4 << "\n"; 40 | } 41 | 42 | int main() 43 | { 44 | ios_base::sync_with_stdio(false); 45 | cin.tie(0); cout.tie(0); 46 | _TestCases_ 47 | solve(); 48 | 49 | return 0; 50 | } 51 | --------------------------------------------------------------------------------