├── LeetCode ├── 2197. Replace Non-Coprime Numbers in Array.cpp ├── 852. Peak Index in a Mountain Array.cpp ├── 1480. Running Sum of 1d Array.cpp ├── 217. Contains Duplicate.cpp ├── 3516. Find Closest Person.cpp ├── 283. Move Zeroes.cpp ├── 3227. Vowels Game in a String.cpp ├── 2011. Final Value of Variable After Performing Operations.cpp ├── 53. Maximum Subarray.cpp ├── 121. Best Time to Buy and Sell Stock.cpp ├── 1502. Can Make Arithmetic Progression From Sequence.cpp ├── 485. Max Consecutive Ones.cpp ├── 3100. Water Bottles II.cpp ├── 2739. Total Distance Traveled.cpp ├── 2749. Minimum Operations to Make the Integer Zero.cpp ├── 3005. Count Elements With Maximum Frequency.cpp ├── 1518. Water Bottles.cpp ├── 11. Container With Most Water.cpp ├── 976. Largest Perimeter Triangle.cpp ├── 704. Binary Search.cpp ├── 167. Two Sum II - Input Array Is Sorted.cpp ├── 1588. Sum of All Odd Length Subarrays.cpp ├── 2221. Find Triangular Sum of an Array.cpp ├── 242. Valid Anagram.cpp ├── 125. Valid Palindrome.cpp ├── 347. Top K Frequent Elements.cpp ├── 1780. Check if Number is a Sum of Powers of Three.cpp ├── 2366. Minimum Replacements to Sort the Array.cpp ├── 611. Valid Triangle Number.cpp ├── 2965. Find Missing and Repeated Values.cpp ├── 3477. Fruits Into Baskets II.cpp ├── 1047. Remove All Adjacent Duplicates In String.cpp ├── 350. Intersection of Two Arrays II.cpp ├── 1317. Convert Integer to the Sum of Two No-Zero Integers.cpp ├── 3147. Taking Maximum Energy From the Mystic Dungeon.cpp ├── 1952. Three Divisors.cpp ├── 1935. Maximum Number of Words You Can Type.cpp ├── 1304. Find N Unique Integers Sum up to Zero.cpp ├── 2273. Find Resultant Array After Removing Anagrams.cpp ├── 128. Longest Consecutive Sequence.cpp ├── 2379. Minimum Recolors to Get K Consecutive Black Blocks.cpp ├── 118. Pascal's Triangle.cpp ├── 35. Search Insert Position.cpp ├── 1351. Count Negative Numbers in a Sorted Matrix.cpp ├── 3350. Adjacent Increasing Subarrays Detection II.cpp ├── 400. Nth Digit.cpp ├── 3349. Adjacent Increasing Subarrays Detection I.cpp ├── 1971. Find if Path Exists in Graph.cpp ├── 1437. Check If All 1's Are at Least Length K Places Away.cpp ├── 415. Add Strings.cpp ├── 2300. Successful Pairs of Spells and Potions.cpp ├── 2327. Number of People Aware of a Secret.cpp ├── 20. Valid Parentheses.cpp ├── 1488. Avoid Flood in The City.cpp ├── 349. Intersection of Two Arrays.cpp ├── 812. Largest Triangle Area.cpp ├── 120. Triangle.cpp ├── 2874. Maximum Value of an Ordered Triplet II.cpp ├── 518. Coin Change II.cpp ├── 3027. Find the Number of Ways to Place People II.cpp ├── 1004. Max Consecutive Ones III.cpp ├── 983. Minimum Cost For Tickets.cpp ├── 3494. Find the Minimum Amount of Time to Brew Potions.cpp ├── 904. Fruit Into Baskets.cpp ├── 808. Soup Servings.cpp ├── 682. Baseball Game.cpp └── 3025. Find the Number of Ways to Place People I.cpp ├── .gitattributes ├── README.md ├── CodeForces ├── 1721 A. Image.cpp ├── 199 A. Hexadecimal's theorem.cpp ├── 4 A. Watermelon.c ├── 41 A. Translation.cpp ├── 228 A. Is your horseshoe on the other hoof.cpp ├── 69 A. Young Physicist.cpp ├── 379 A. New Year Candles.cpp ├── 1764 A. Doremy's Paint.cpp ├── 282 A. Bit++.c ├── 71 A. Way Too Long Words.c ├── 231 A. Team.c ├── 1765 M. Minimum LCM.cpp ├── 118 A. String Task.cpp ├── 1660 A. Vasya and Coins.cpp ├── 263 A. Beautiful Matrix.cpp ├── 133 A. HQ9+.cpp ├── GYM 104077 C. Clone Ranran.cpp ├── GYM 564323 J. Resli utiful Pair.cpp ├── 1579 A. Casimir's String Solitaire.c ├── 339 A. Helpful Maths.cpp ├── 304 A. Pythagorean Theorem II.cpp ├── 32 B. Borze.cpp ├── 236 A. Boy or Girl.cpp ├── 281 A. Word Capitalization.cpp ├── 112 A. Petya and Strings.cpp ├── GYM 564323 L. Ammar utiful Permutations.cpp ├── 266 B. Queue at the School.cpp ├── 4 C. Registration system.cpp ├── GYM 102141 G. Decode The Alien Message.cpp ├── 110 A. Nearly Lucky Number.cpp ├── 1765 B. Broken Keyboard.cpp ├── GYM 556326 E. Fatigue-Fighting Vacation.cpp ├── 1512 A. Spy Detected!.c ├── 1748 A. The Ultimate Square.cpp ├── 1743 A. Password.cpp ├── 1750 A. Indirect Sort.cpp ├── 266 A. Stones on the Table.cpp ├── 1747 A. Two Groups.cpp ├── GYM 556326 I. Lexicographical Challenge.cpp ├── 1742 A. Sum.cpp ├── 1660 B. Vlad and Candies.cpp ├── 1742 C. Stripes.cpp ├── 1761 A. Two Permutations.cpp ├── GYM 556326 H. Investigating Zeroes and Ones.cpp ├── 1758 A. SSeeeeiinngg DDoouubbllee.cpp ├── 1760 A. Medium Number.cpp ├── 1553 A. Digits Sum.cpp ├── 22 A. Second Order Statistics.cpp ├── 1669 A. Division.cpp ├── 1760 B. Atilla's Favorite Problem.cpp ├── 1729 A. Two Elevators.cpp ├── 1746 A. Maxmina.cpp ├── 1759 A. Yes-Yes.cpp ├── 271 A. Beautiful Year.cpp ├── 1749 A. Cowardly Rooks.cpp ├── 1764 B. Doremy's Perfect Math Class.cpp ├── 1743 B. Permutation Value.cpp ├── 1742 B. Increasing.cpp ├── 1754 B. Kevin and Permutation.cpp ├── 1722 A. Spell Check.cpp ├── 1754 A. Technical Support.cpp ├── 59 A. Word.cpp ├── 1592 A. Gamer Hemose.cpp ├── 1747 B. BAN BAN.cpp ├── 1721 B. Deadly Laser.cpp ├── 1732 B. Ugu.cpp ├── 1720 A. Burenka Plays with Fractions.cpp ├── 1722 B. Colourblindness.cpp ├── 1758 B. XOR = Average.cpp ├── 469 A. I Wanna Be the Guy.cpp ├── GYM 104077 J. Strange Sum.cpp ├── 1650 B. DIV + MOD.cpp ├── 1617 B. GCD Problem.cpp ├── 1735 B. Tea with Tangerines.cpp ├── 1714 A. Everyone Loves to Sleep.cpp ├── 1731 A. Joey Takes Money.cpp ├── 1791 A. Codeforces Checking.cpp ├── 1759 C. Thermostat.cpp ├── 1675 B. Make It Increasing.cpp ├── 1766 A. Extremely Round.cpp ├── 1793 A. Yet Another Promotion.cpp ├── 1760 C. Advantage.cpp ├── 1473 A. Replacing Elements.cpp ├── 1689 B. Mystic Permutation.cpp ├── 1749 B. Death's Blessing.cpp ├── 1741 B. Funny Permutation.cpp └── 1730 A. Planets.cpp ├── Beecrowd ├── 1000 - Hello World!.c ├── 1001 - Extremely Basic.c ├── 1003 - Simple Sum.c ├── 1004 - Simple Product.c ├── 1002 - Area of a Circle.c ├── 1005 - Average 1.c └── 1006 - Average 2.c ├── Timus └── 1000. A+B Problem.cpp ├── CodeChef ├── LP0TO101 - A. Number Mirror.cpp ├── START116D A. Minimum Wage.cpp ├── LP0TO101 - C. Find Remainder.cpp ├── LP0TO101 - E. Add_Two_Numbers.cpp ├── LP0TO101 - I. First_and_Last_Digit.cpp ├── LP0TO101 - G. Chef_And_Operators.cpp ├── LP0TO101 - F. Reverse_The_Number.cpp ├── LP0TO101 - D. Sum of Digits.cpp ├── LP0TO101 - H. ATM.cpp ├── LP0TO101 - B. Enormous Input Test.cpp └── START105C - C. Dull Operation.cpp ├── CodeMarshal ├── (icpc-dhaka-2016-preli) A. A Directed Graph.cpp ├── (icpc-dhaka-20-preli) J. COVID 19.cpp ├── (diu_takeoff_fall_19) A. I will be the one.cpp ├── (icpc-dhaka-preli-18) A. Welcome.cpp ├── (icpc-dhaka-19-preli) I. Almost Forgot to Welcome.cpp ├── (icpc-dhaka-preli-2017) F. Coldplay.cpp └── (icpc-dhaka-20) K. Fare Thee Well My Friends.cpp ├── LightOJ └── LOJ-1000. Greetings from LightOJ.cpp ├── Dimik OJ (Part of LightOJ) ├── Problem 3-Descending Number.cpp ├── Problem 1-Even-Odd 1.cpp ├── Problem 21-Reverse Word.cpp ├── Problem 26-Alien Gupi.cpp ├── Problem 11-Factorial.cpp ├── Problem 4-Divisor.cpp ├── Problem 5-Box 1.cpp ├── Problem 19-Word Count 1.cpp ├── Problem 24-Alternate Elements.cpp ├── Problem 6-Summation.cpp ├── Problem 10-Run Rate 1.cpp ├── Problem 20-Word Count 2.cpp ├── Problem 29-Character Recognition.cpp ├── Problem 2-Even-Odd 2.cpp ├── Problem 27-Armstrong Number.cpp ├── Problem 23-Letter to Number.cpp ├── Problem 14-Character Frequency.cpp ├── Problem 8-Small to Large.cpp ├── Problem 22-Prime Number.cpp ├── Problem 18-Vowel Consonant.cpp ├── Problem 35-Out of a Circle.cpp ├── Problem 37-Number Disaster.cpp ├── Problem 40-Sum of Series 1.cpp ├── Problem 39-Palindrome.cpp ├── Problem 16-Word Disaster.cpp ├── Problem 43-Calculation.cpp ├── Problem 38-Diamond Kingdom.cpp ├── Problem 42-Sum of Series 3.cpp ├── Problem 28-Random Array.cpp ├── Problem 46-Area of Triangle.cpp ├── Problem 9-Square Number.cpp └── Problem 12-Factorial 100.cpp ├── AtCoder ├── ABC 279 A - wwwvvvvvv.cpp ├── ABC 280 C - Extra Charactor.cpp ├── ABC 288 A - Many A+B Problems.cpp ├── ABC 280 B - Inverse Prefix Sum.cpp ├── ARC 087 C - Good Sequence.cpp ├── ABC 281 A - Count Down.cpp ├── ABC 280 A - Pawn on a Grid.cpp ├── ABC 292 A - CAPS LOCK.cpp ├── ABC 118 A - A - B +- A.cpp ├── ABC 288 B - Qualification Contest.cpp └── ABC 291 A - camel Case.cpp ├── CSES Problem Set ├── All IN ONE │ ├── 1621 - Distinct Numbers.cpp │ ├── 1068 - Weird Algorithm.cpp │ ├── 1650 - Range Xor Queries.cpp │ ├── 1094 - Increasing Array.cpp │ ├── 1083 - Missing Number.cpp │ ├── 1070 - Permutations.cpp │ ├── 1069 - Repetitions.cpp │ ├── 1617 - Bit Strings.cpp │ └── 1634. Minimizing Coins (Iterative Approach).cpp ├── Sorting and Searching │ └── 1. Distinct Numbers.cpp ├── Introductory Problems │ ├── 1. Weird Algorithm.cpp │ ├── 4. Increasing Array.cpp │ ├── 2. Missing Number.cpp │ ├── 5. Permutations.cpp │ ├── 3. Repetitions.cpp │ └── 9. Bit Strings.cpp ├── Range Queries │ └── 5. Range Xor Queries.cpp └── Dynamic Programming │ └── 2. Minimizing Coins (Iterative Approach).cpp ├── HackerEarth ├── LexoGeek.cpp ├── The_Palindrome.cpp └── Monk_s_Encounter_with_Polynomial.cpp ├── AIZU Online Judge ├── ITP1_6_D. Matrix Vector Multiplication.cpp └── ITP1_3_D. How Many Divisors.cpp ├── GeeksForGeeks Practice ├── Find the Frequency.cpp ├── Sum of Digit is Pallindrome or not.cpp ├── Sum of large numbers.cpp ├── Queue Push & Pop.cpp ├── Queue Reversal.cpp ├── Twice Counter.cpp ├── Square root of a number.cpp ├── Reverse First K elements of Queue.cpp └── Special Stack.cpp ├── SPOJ └── BSEARCH1 - Binary search.cpp └── LICENSE /LeetCode/2197. Replace Non-Coprime Numbers in Array.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Online Judge Solution 2 | Solutions of various online judge problems. 3 | -------------------------------------------------------------------------------- /CodeForces/1721 A. Image.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mehedi-Hasan-Rabbi/Online-Judge-Solution/HEAD/CodeForces/1721 A. Image.cpp -------------------------------------------------------------------------------- /Beecrowd/1000 - Hello World!.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | printf("Hello World!\n"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Beecrowd/1001 - Extremely Basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int a, b, x; 5 | scanf("%d %d", &a, &b); 6 | x = a + b; 7 | printf("X = %d\n", x); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Timus/1000. A+B Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int x, y; cin >> x >> y; 7 | cout << x+y << endl; 8 | return 0; 9 | } -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - A. Number Mirror.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int x; 6 | cin >> x; 7 | cout << x << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /Beecrowd/1003 - Simple Sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | int A,B,SOMA; 5 | scanf("%d %d", &A,&B); 6 | SOMA = A + B; 7 | printf("SOMA = %d\n", SOMA); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Beecrowd/1004 - Simple Product.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | int A,B,PROD; 5 | scanf("%d %d", &A,&B); 6 | PROD = A * B; 7 | printf("PROD = %d\n", PROD); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /CodeChef/START116D A. Minimum Wage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; cin >> n; 6 | if (n > 11) cout << "YES" << "\n"; 7 | else cout << "NO" << "\n"; 8 | } 9 | -------------------------------------------------------------------------------- /CodeForces/199 A. Hexadecimal's theorem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | cout << "0 0 " << n << endl; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /Beecrowd/1002 - Area of a Circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | double A,n,r; 5 | n = 3.14159; 6 | scanf("%lf", &r); 7 | A = n*(r*r); 8 | printf("A=%0.4lf\n",A); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /LeetCode/852. Peak Index in a Mountain Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int peakIndexInMountainArray(vector& arr) { 4 | int i = max_element(arr.begin(), arr.end()) - arr.begin(); 5 | return i; 6 | } 7 | }; -------------------------------------------------------------------------------- /CodeMarshal/(icpc-dhaka-2016-preli) A. A Directed Graph.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | cout << "68 0 0" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /LeetCode/1480. Running Sum of 1d Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector runningSum(vector& nums) { 4 | for (int i = 1; i < nums.size(); i++) 5 | nums[i] = nums[i] + nums[i - 1]; 6 | return nums; 7 | } 8 | }; -------------------------------------------------------------------------------- /Beecrowd/1005 - Average 1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | double A,B,MEDIA; 5 | scanf("%lf %lf", &A,&B); 6 | A = A * 3.5; 7 | B = B * 7.5; 8 | MEDIA =(A+B) / 11; 9 | printf("MEDIA = %0.5lf\n",MEDIA); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - C. Find Remainder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a, b; 9 | cin>>a>>b; 10 | cout< 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int n; cin >> n; 8 | int ans = (n/6)+1; 9 | cout << ans << endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /CodeMarshal/(diu_takeoff_fall_19) A. I will be the one.cpp: -------------------------------------------------------------------------------- 1 | // https://algo.codemarshal.org/contests/diu_takeoff_fall_19/problems/A 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | cout << "DJ NAJ, I will be the one" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /Beecrowd/1006 - Average 2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | double A,B,C,MEDIA; 5 | scanf("%lf %lf %lf", &A,&B,&C); 6 | A = A * 2; 7 | B = B * 3; 8 | C = C * 5; 9 | MEDIA =(A+B+C) / 10; 10 | printf("MEDIA = %0.1lf\n",MEDIA); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /CodeMarshal/(icpc-dhaka-preli-18) A. Welcome.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | cout << "Welcome to ACM ICPC Dhaka Regional Online Preliminary Contest, 2018" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /LeetCode/217. Contains Duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& nums) { 4 | set st; 5 | for (auto u: nums) st.insert(u); 6 | 7 | if (nums.size() == st.size()) return false; 8 | else return true; 9 | } 10 | }; -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - E. Add_Two_Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | int a,b; 9 | while(t--){ 10 | int sum=0; 11 | cin>>a>>b; 12 | sum=a+b; 13 | cout< abs(y - z)) 7 | return 2; 8 | 9 | return 0; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /CodeForces/4 A. Watermelon.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int w; 5 | scanf("%d",&w); 6 | if (w>=1 && w<=100) 7 | { 8 | if (w%2==0 && w!=2) 9 | printf("YES\n"); 10 | else 11 | printf("NO\n"); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /CodeMarshal/(icpc-dhaka-19-preli) I. Almost Forgot to Welcome.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | cout << "Welcome to ICPC Dhaka Regional Online Preliminary Contest, 2019" << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /LightOJ/LOJ-1000. Greetings from LightOJ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int test,num1,num2; 5 | scanf("%d",&test); 6 | for (int i=1;i<=test;i++) 7 | { 8 | scanf("%d %d",&num1,&num2); 9 | printf("Case %d: %d\n",i,num1+num2); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /CodeMarshal/(icpc-dhaka-preli-2017) F. Coldplay.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int p, q, y; 8 | cin >> p >> q >> y; 9 | int ans = (y * (52 * ((5 * p) + (2 * q)))); 10 | cout << ans << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /CodeMarshal/(icpc-dhaka-20) K. Fare Thee Well My Friends.cpp: -------------------------------------------------------------------------------- 1 | // https://algo.codemarshal.org/contests/icpc-dhaka-20/problems/K 2 | // https://drive.google.com/file/d/18jGDn3YRcgJ61tUFruMvMKqGiHMw1xTY/view 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | cout << 26 << endl; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /CodeForces/41 A. Translation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | string s, t; 6 | getline(cin, s); 7 | getline(cin, t); 8 | 9 | reverse(s.begin(), s.end()); 10 | 11 | if(s == t) 12 | cout << "YES" << endl; 13 | else 14 | cout << "NO" << endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CodeForces/228 A. Is your horseshoe on the other hoof.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | 6 | int main(void) 7 | { 8 | ll color[4]; 9 | for(ll i=0; i<4; i++) 10 | cin >> color[i]; 11 | 12 | set uni(color, color+4); 13 | 14 | cout<<4-uni.size()<<'\n'; 15 | } 16 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 3-Descending Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | for (int i=1000; i>=1; i--) 8 | { 9 | if (i%5==0 & i!=1000) 10 | cout << endl; 11 | cout << i << ' '; 12 | } 13 | cout << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LeetCode/283. Move Zeroes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& nums) { 4 | int zero = 0; 5 | for (int i = 0; i < (int) nums.size(); i++) { 6 | if (nums[i] != 0) { 7 | swap(nums[i], nums[zero]); 8 | zero++; 9 | } 10 | } 11 | } 12 | }; -------------------------------------------------------------------------------- /LeetCode/3227. Vowels Game in a String.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool doesAliceWin(string s) { 4 | int vowel = 0; 5 | for (auto &u: s) { 6 | if (u == 'a' || u == 'e' || u == 'i' || u == 'o' || u == 'u') 7 | vowel++; 8 | } 9 | 10 | return vowel != 0; 11 | } 12 | }; -------------------------------------------------------------------------------- /CodeForces/69 A. Young Physicist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main () 5 | { 6 | int n, a, b, c, d=0, e=0, f=0; 7 | cin >> n; 8 | while (n--) 9 | { 10 | cin >> a >> b >> c; 11 | d += a; 12 | e += b; 13 | f += c; 14 | } 15 | cout << (d | e | f ? "NO" : "YES"); 16 | } 17 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 1-Even-Odd 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) 4 | { 5 | int t, n; 6 | cin >> t; 7 | while(t--) 8 | { 9 | cin >> n; 10 | if (n%2 == 0) 11 | cout << "even" << endl; 12 | else 13 | cout << "odd" << endl; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /AtCoder/ABC 279 A - wwwvvvvvv.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string s; 6 | cin >> s; 7 | 8 | int ans = 0; 9 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int a, b, res = 1; 8 | cin >> a >> b; 9 | 10 | for(int i=1; i<=a; i++) 11 | { 12 | if (i%b == 0) 13 | { 14 | res++; 15 | } 16 | res++; 17 | } 18 | cout << res << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /CodeForces/1764 A. Doremy's Paint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | int n; 11 | cin >> n; 12 | int a[n]; 13 | for (int i=0; i> a[i]; 15 | 16 | cout << 1 << " " << n << endl; 17 | } 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1621 - Distinct Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long int 5 | 6 | int main() { 7 | set s; 8 | 9 | ll n, x; 10 | cin >> n; 11 | 12 | for(ll i=1; i<=n; i++) 13 | { 14 | cin >> x; 15 | s.insert(x); 16 | } 17 | 18 | cout << s.size() << endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - I. First_and_Last_Digit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | #define el endl; 5 | 6 | int main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int rem = n%10; 15 | while(n>9) 16 | { 17 | n = n/10; 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | #define ll long long int 5 | 6 | int main() { 7 | set s; 8 | 9 | ll n, x; 10 | cin >> n; 11 | 12 | for(ll i=1; i<=n; i++) 13 | { 14 | cin >> x; 15 | s.insert(x); 16 | } 17 | 18 | cout << s.size() << endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /CodeForces/282 A. Bit++.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int t, x=0; 5 | scanf("%d", &t); 6 | while(t--) 7 | { 8 | char bit[3]; 9 | for (int i=0; i<3; i++) 10 | scanf(" %c", &bit[i]); 11 | if (bit[0]=='+' || bit[2]=='+') 12 | x++; 13 | else 14 | x--; 15 | } 16 | printf("%d\n", x); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /LeetCode/2011. Final Value of Variable After Performing Operations.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int finalValueAfterOperations(vector& operations) { 4 | int ans = 0; 5 | 6 | for (auto &u: operations) { 7 | if (u == "++X" or u == "X++") 8 | ans++; 9 | else 10 | ans--; 11 | } 12 | 13 | return ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /LeetCode/53. Maximum Subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& nums) { 4 | // kadane's algorithm 5 | int ans = INT_MIN, sum = 0; 6 | 7 | for (int i = 0; i < nums.size(); i++) 8 | { 9 | sum += nums[i]; 10 | ans = max(sum, ans); 11 | if (sum < 0) sum = 0; 12 | } 13 | 14 | return ans; 15 | } 16 | }; -------------------------------------------------------------------------------- /LeetCode/121. Best Time to Buy and Sell Stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int ans = INT32_MIN; 5 | int mn = prices[0]; 6 | 7 | for (int i = 0; i < (int)prices.size(); i++) { 8 | mn = min(prices[i], mn); 9 | 10 | ans = max((prices[i] - mn), ans); 11 | } 12 | 13 | return (ans > 0 ? ans : 0); 14 | } 15 | }; -------------------------------------------------------------------------------- /LeetCode/1502. Can Make Arithmetic Progression From Sequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canMakeArithmeticProgression(vector& arr) { 4 | sort(arr.begin(), arr.end()); 5 | 6 | int d = arr[1] - arr[0]; 7 | for (int i = 2; i < arr.size(); i++) 8 | { 9 | if (arr[i] - arr[i - 1] != d) 10 | return false; 11 | } 12 | return true; 13 | } 14 | }; -------------------------------------------------------------------------------- /LeetCode/485. Max Consecutive Ones.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMaxConsecutiveOnes(vector& nums) { 4 | int ans = 0, cnt = 0; 5 | for (auto &u: nums) { 6 | if (u == 1) cnt++; 7 | else { 8 | ans = max(ans, cnt); 9 | cnt = 0; 10 | } 11 | } 12 | 13 | ans = max(ans, cnt); 14 | 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - G. Chef_And_Operators.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int x, y; 7 | cin >> x >> y; 8 | if (x>y) 9 | cout << ">" << endl; 10 | else if (x=0; i--) 15 | { 16 | cout << s[i]; 17 | } 18 | cout << '\n'; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1068 - Weird Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | long long n; 7 | cin >> n; 8 | cout << n ; 9 | while(n!=1) 10 | { 11 | if(n%2==0) 12 | { 13 | n = n/2; 14 | cout << " " << n; 15 | } 16 | else 17 | { 18 | n = (n*3)+1; 19 | cout << " " << n; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - H. ATM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.precision(2); 9 | 10 | int a; 11 | float b; 12 | cin >> a >> b; 13 | 14 | if ((a%5==0) && (b-a-0.5>=0)) 15 | { 16 | cout << fixed << b-a-0.5 << endl; 17 | } 18 | else 19 | { 20 | cout << fixed << b << endl; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 26-Alien Gupi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | double X; 7 | cin >> X; 8 | 9 | int count = 0; 10 | while(X>1.0) 11 | { 12 | X = X/2; 13 | count++; 14 | } 15 | cout << count << " days" << '\n'; 16 | } 17 | 18 | int main(void) 19 | { 20 | int t=1; 21 | cin>>t; 22 | while(t--) 23 | { 24 | solve(); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/1. Weird Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | long long n; 7 | cin >> n; 8 | cout << n ; 9 | while(n!=1) 10 | { 11 | if(n%2==0) 12 | { 13 | n = n/2; 14 | cout << " " << n; 15 | } 16 | else 17 | { 18 | n = (n*3)+1; 19 | cout << " " << n; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /HackerEarth/LexoGeek.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | string s; 7 | cin >> s; 8 | 9 | if (next_permutation(s.begin(), s.end())) 10 | cout << s << endl; 11 | else cout << "no answer" << endl; 12 | } 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | 19 | int t; 20 | cin >> t; 21 | while (t--) 22 | { 23 | solve(); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /LeetCode/2749. Minimum Operations to Make the Integer Zero.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int makeTheIntegerZero(int num1, int num2) { 4 | for (int k = 1; k <= 60; k++) { 5 | long long val = (1LL * num1) - (1LL * k * num2); 6 | if (val < 0) continue; 7 | 8 | int setBitCount = __builtin_popcountll(val); 9 | if (setBitCount <= k and k <= val) 10 | return k; 11 | } 12 | 13 | return -1; 14 | } 15 | }; -------------------------------------------------------------------------------- /LeetCode/3005. Count Elements With Maximum Frequency.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxFrequencyElements(vector& nums) { 4 | vector freq(105, 0); 5 | int mx = 0; 6 | for (auto u: nums) { 7 | freq[u]++; 8 | mx = max(mx, freq[u]); 9 | } 10 | 11 | int ans = 0; 12 | for (auto u: nums) { 13 | if (freq[u] == mx) 14 | ans++; 15 | } 16 | 17 | return ans; 18 | } 19 | }; -------------------------------------------------------------------------------- /CodeChef/LP0TO101 - B. Enormous Input Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | 9 | int n,k; 10 | cin >> n >> k; 11 | 12 | int count=0; 13 | for (int i=0;i<=n-1;i++) 14 | { 15 | int a; 16 | cin >> a; 17 | if (a%k==0) 18 | { 19 | count++; 20 | } 21 | } 22 | 23 | cout << count << endl; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeForces/71 A. Way Too Long Words.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int testCase; 6 | scanf("%d",&testCase); 7 | for (int i=0;i10) 13 | { 14 | printf("%c%d%c\n",ch[0],length-2,ch[length-1]); 15 | } 16 | else 17 | printf("%s\n",ch); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 11-Factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n; 7 | cin >> n; 8 | long long int factorial = 1; 9 | 10 | for (int i=2; i<=n; i++) 11 | { 12 | factorial = factorial * i; 13 | } 14 | cout << factorial << endl; 15 | } 16 | 17 | int main(void) 18 | { 19 | int t; 20 | cin >> t; 21 | 22 | while (t--) 23 | { 24 | solve(); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LeetCode/1518. Water Bottles.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numWaterBottles(int numBottles, int numExchange) { 4 | int ans = numBottles, remain = 0; 5 | 6 | while (numBottles >= numExchange) { 7 | remain = numBottles % numExchange; 8 | numBottles = numBottles / numExchange; 9 | 10 | ans += numBottles; 11 | 12 | numBottles += remain; 13 | } 14 | 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /CodeForces/231 A. Team.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int testCase,i,j,count=0,solve=0; 5 | scanf("%d",&testCase); 6 | for (i=0;i=2) 16 | solve++; 17 | count=0; 18 | } 19 | printf("%d\n",solve); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 4-Divisor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int t=1, n; 7 | cin>>t; 8 | for (int i=1; i<=t; i++) 9 | { 10 | cin >> n; 11 | cout << "Case " << i << ":"; 12 | for (int j=1; j<=n; j++) 13 | { 14 | if(n%j == 0) 15 | { 16 | cout << ' ' << j; 17 | } 18 | } 19 | cout << endl; 20 | } 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /LeetCode/11. Container With Most Water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& height) { 4 | int l = 0, r = height.size() - 1; 5 | int ans = 0; 6 | 7 | while (l < r) { 8 | int mn = min(height[l], height[r]); 9 | int res = mn * (r - l); 10 | ans = max(res, ans); 11 | 12 | if (height[l] <= height[r]) l++; 13 | else if (height[l] > height[r]) r--; 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /HackerEarth/The_Palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | string s; cin >> s; 7 | string test = s; 8 | 9 | reverse(test.begin(), test.end()); 10 | 11 | if (s == test) cout << "Yes" << '\n'; 12 | else cout << "No" << '\n'; 13 | } 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | 19 | int t; cin >> t; 20 | while (t--) 21 | { 22 | solve(); 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /LeetCode/976. Largest Perimeter Triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestPerimeter(vector& nums) { 4 | sort(nums.begin(), nums.end(), greater()); 5 | 6 | int ans = 0; 7 | for (int i = 0; i + 2 < nums.size(); i++) { 8 | int a = nums[i]; 9 | int b = nums[i + 1]; 10 | int c = nums[i + 2]; 11 | 12 | if (a < b + c) 13 | ans = max(ans, (a + b + c)); 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/704. Binary Search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | int l = 0, r = nums.size() - 1; 5 | int ans = -1; 6 | 7 | while (l <= r) { 8 | int mid = l + (r - l) / 2; 9 | if (nums[mid] == target) { 10 | ans = mid; 11 | break; 12 | } 13 | else if (nums[mid] < target) l = mid + 1; 14 | else r = mid - 1; 15 | } 16 | 17 | return ans; 18 | } 19 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 5-Box 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | for (int i=0; i> t; 21 | 22 | while(t--) 23 | { 24 | solve(); 25 | if (t != 0) 26 | cout << endl; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /LeetCode/167. Two Sum II - Input Array Is Sorted.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& numbers, int target) { 4 | for (int i = 0; i < numbers.size(); i++) { 5 | int val = target - numbers[i]; 6 | int lower = lower_bound(numbers.begin()+i+1, numbers.end(), val) - numbers.begin(); 7 | 8 | if (lower < numbers.size() && numbers[lower] == val) 9 | return { i + 1, lower + 1 }; 10 | } 11 | 12 | return { -1, -1 }; 13 | } 14 | }; -------------------------------------------------------------------------------- /CodeForces/1765 M. Minimum LCM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int t, n; 5 | 6 | int main() 7 | { 8 | cin >> t; 9 | while (t--) 10 | { 11 | cin >> n; 12 | int prime = n; 13 | for (int d = 2; d * d <= n; ++d) 14 | if (n % d == 0) 15 | { 16 | prime = d; 17 | break; 18 | } 19 | int piece = n / prime; 20 | cout << piece << " " << n - piece << '\n'; 21 | } 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /CodeForces/118 A. String Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isVowel (char c) { 5 | return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); 6 | } 7 | 8 | int main() 9 | { 10 | string s, ans; 11 | cin >> s; 12 | 13 | for (auto &&i : s) 14 | { 15 | char c = tolower(i); 16 | 17 | if (!isVowel(c)) { 18 | ans += '.'; 19 | ans += c; 20 | } 21 | } 22 | 23 | cout << ans << endl; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 19-Word Count 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | char s[10001]; 7 | scanf(" %[^\n]", s); 8 | 9 | int counter=0; 10 | for (int i=0; s[i]!='\0'; i++) 11 | { 12 | if (s[i]==' ') 13 | counter++; 14 | } 15 | cout << "Count = " << counter+1 << '\n'; 16 | } 17 | 18 | int main(void) 19 | { 20 | int t; 21 | cin >> t; 22 | 23 | while(t--) 24 | { 25 | solve(); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /LeetCode/1588. Sum of All Odd Length Subarrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sumOddLengthSubarrays(vector& arr) { 4 | int n = arr.size(); 5 | vector pref(n + 1, 0); 6 | for (int i = 1; i <= n; i++) 7 | pref[i] = pref[i - 1] + arr[i - 1]; 8 | 9 | int ans = 0; 10 | for (int l = 1; l <= n; l += 2) 11 | { 12 | for (int i = l; i <= n; i++) 13 | ans += pref[i] - pref[i - l]; 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/2221. Find Triangular Sum of an Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int triangularSum(vector& nums) { 4 | int n = nums.size(); 5 | vector newNums = nums; 6 | 7 | while (newNums.size() != 1) { 8 | newNums.assign(nums.size() - 1, 0); 9 | 10 | for (int i = 0; i < newNums.size(); i++) { 11 | newNums[i] = (nums[i] + nums[i + 1]) % 10; 12 | } 13 | 14 | nums = newNums; 15 | } 16 | 17 | return newNums[0]; 18 | } 19 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 24-Alternate Elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int arr[n]; 10 | for (int i=0; i> arr[i]; 12 | 13 | cout << arr[0]; 14 | for (int i=2; i>t; 24 | while(t--) 25 | { 26 | solve(); 27 | } 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /LeetCode/242. Valid Anagram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isAnagram(string s, string t) { 4 | if (s.size() != t.size()) return false; 5 | 6 | int count[30]; 7 | memset(count, 0, sizeof(count)); 8 | 9 | for (int i = 0; i < s.size(); i++) { 10 | count[s[i] - 'a']++; 11 | } 12 | 13 | for (int i = 0; i < t.size(); i++) { 14 | if (count[t[i] - 'a'] > 0) count[t[i] - 'a']--; 15 | else return false; 16 | } 17 | 18 | return true; 19 | } 20 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 6-Summation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n, sum = 0; 7 | cin >> n; 8 | 9 | for (int i=5; i>=1; i--) 10 | { 11 | if (i==5 || i==1) 12 | { 13 | sum = sum + (n%10); 14 | } 15 | n = n/10; 16 | } 17 | cout << "Sum = " << sum << endl; 18 | } 19 | 20 | int main(void) 21 | { 22 | int t; 23 | cin >> t; 24 | 25 | while(t--) 26 | { 27 | solve(); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1650 - Range Xor Queries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int mx = 2e5 + 123; 5 | int a[mx], prefXOR[mx]; 6 | 7 | int main () 8 | { 9 | int n, q; cin >> n >> q; 10 | for (int i = 1; i <= n; i++) 11 | cin >> a[i]; 12 | 13 | for (int i = 1; i <= n; i++) 14 | prefXOR[i] = prefXOR[i - 1] ^ a[i]; 15 | 16 | while (q--) 17 | { 18 | int l, r; cin >> l >> r; 19 | cout << (prefXOR[r] ^ prefXOR[l - 1]) << endl; 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /CSES Problem Set/Range Queries/5. Range Xor Queries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int mx = 2e5 + 123; 5 | int a[mx], prefXOR[mx]; 6 | 7 | int main () 8 | { 9 | int n, q; cin >> n >> q; 10 | for (int i = 1; i <= n; i++) 11 | cin >> a[i]; 12 | 13 | for (int i = 1; i <= n; i++) 14 | prefXOR[i] = prefXOR[i - 1] ^ a[i]; 15 | 16 | while (q--) 17 | { 18 | int l, r; cin >> l >> r; 19 | cout << (prefXOR[r] ^ prefXOR[l - 1]) << endl; 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /CodeForces/1660 A. Vasya and Coins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int t; 8 | cin >> t; 9 | 10 | while(t--) 11 | { 12 | int a, b; 13 | cin >> a >> b; 14 | 15 | if (a==0 && b==0) 16 | cout << "1" << endl; 17 | 18 | else if (a==0) 19 | cout << "1" << endl; 20 | 21 | else if (b == 0) 22 | cout << a+1 << endl; 23 | 24 | else 25 | cout << (a + (b*2) + 1) << endl; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /LeetCode/125. Valid Palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPalindrome(string s) { 4 | string str; 5 | for (auto u: s) { 6 | if ('a' <= u and u <= 'z') str.push_back(u); 7 | else if ('A' <= u and u <= 'Z') str.push_back(u + 32); 8 | else if ('0' <= u and u <= '9') str.push_back(u); 9 | } 10 | 11 | int l = 0, r = str.size() - 1; 12 | while (l <= r) { 13 | if (str[l] != str[r]) return false; 14 | l++, r--; 15 | } 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/347. Top K Frequent Elements.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector topKFrequent(vector& nums, int k) { 4 | map freq; 5 | vector> arr; 6 | vector ans; 7 | 8 | for (auto u: nums) freq[u]++; 9 | for (auto [val, cnt]: freq) 10 | arr.push_back({cnt, val}); 11 | 12 | sort(arr.begin(), arr.end(), greater>()); 13 | 14 | for (int i = 0; i < k; i++) 15 | ans.push_back(arr[i].second); 16 | 17 | return ans; 18 | } 19 | }; -------------------------------------------------------------------------------- /LeetCode/1780. Check if Number is a Sum of Powers of Three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPowersOfThree(int n) { 4 | vector pow; 5 | int val = 1; 6 | for (int i = 0; val <= 1e7; i++) { 7 | pow.push_back(val); 8 | val = val * 3; 9 | } 10 | 11 | int sz = pow.size(); 12 | for (int i = sz - 1; i >= 0; i--) { 13 | if (n >= pow[i]) 14 | n -= pow[i]; 15 | 16 | if (n == 0) return true; 17 | } 18 | 19 | return false; 20 | } 21 | }; -------------------------------------------------------------------------------- /LeetCode/2366. Minimum Replacements to Sort the Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minimumReplacement(vector& nums) { 4 | int curr = nums.back(); 5 | long long ans = 0; 6 | for (int i = nums.size() - 2; i >= 0; i--) 7 | { 8 | if (nums[i] <= curr) curr = nums[i]; 9 | else { 10 | int part = ceil( (double) nums[i] / curr ); 11 | ans += (part - 1); 12 | curr = nums[i] / part; 13 | } 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /CodeForces/263 A. Beautiful Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int matrix[5][5], row, col; 7 | for (int i=0; i<5; i++) 8 | { 9 | for (int j=0; j<5; j++) 10 | { 11 | cin >> matrix[i][j]; 12 | if (matrix[i][j] == 1) 13 | { 14 | row = i; 15 | col = j; 16 | } 17 | } 18 | } 19 | int move_row = abs(row-2); 20 | int move_col = abs(col-2); 21 | 22 | cout << move_col + move_row << '\n'; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /LeetCode/611. Valid Triangle Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int triangleNumber(vector& nums) { 4 | sort(nums.begin(), nums.end()); 5 | int n = nums.size(); 6 | int ans = 0; 7 | 8 | for (int i = 0; i + 2 < n; i++) { 9 | for (int j = i + 1; j + 1 < n; j++) { 10 | int val = nums[i] + nums[j]; 11 | 12 | int idx = lower_bound(nums.begin() + j + 1, nums.end(), val) - nums.begin(); 13 | 14 | ans += (idx - j - 1); 15 | } 16 | } 17 | 18 | return ans; 19 | } 20 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 10-Run Rate 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, run1, run2, ball, balldone; 7 | double present_rate, wishing_rate; 8 | 9 | cin >> n; 10 | while(n--){ 11 | cin >> run1 >> run2 >> ball; 12 | balldone = 300 - ball; 13 | present_rate = ((run2*1.0) / balldone) * 6.0; 14 | 15 | if (run2 > run1) 16 | wishing_rate = 0.0; 17 | else 18 | wishing_rate = (((run1 - run2 + 1) * 1.0) / ball) * 6.0; 19 | 20 | printf("%0.2lf %0.2lf\n",present_rate,wishing_rate); 21 | } 22 | } -------------------------------------------------------------------------------- /LeetCode/2965. Find Missing and Repeated Values.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findMissingAndRepeatedValues(vector>& grid) { 4 | int n = grid.size(); 5 | vector freq(n * n + 1, 0); 6 | 7 | for (auto vec: grid) { 8 | for (auto u: vec) 9 | freq[u]++; 10 | } 11 | 12 | int twice = -1, missing = -1; 13 | for (int i = 1; i <= (n * n); i++) { 14 | if (freq[i] == 0) missing = i; 15 | if (freq[i] == 2) twice = i; 16 | } 17 | 18 | return {twice, missing}; 19 | } 20 | }; -------------------------------------------------------------------------------- /LeetCode/3477. Fruits Into Baskets II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numOfUnplacedFruits(vector& fruits, vector& baskets) { 4 | int n = (int)fruits.size(); 5 | 6 | vector vis(n, false); 7 | int ans = n; 8 | 9 | for (auto fruit : fruits) { 10 | for (int i = 0; i < n; i++) { 11 | if (baskets[i] >= fruit and vis[i] == false) { 12 | vis[i] = true; 13 | ans--; 14 | break; 15 | } 16 | } 17 | } 18 | 19 | return ans; 20 | } 21 | }; -------------------------------------------------------------------------------- /CodeForces/133 A. HQ9+.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | string str; 8 | getline (cin, str); 9 | 10 | 11 | int flag = 0; 12 | for(int i=0; i 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | int a, b, c; 7 | void solve(void) 8 | { 9 | cin >> a >> b >> c; 10 | int cp = 1, mn = 0, prb = 0, res = 1e18; 11 | for (int i = 0; i < 32; i++) 12 | { 13 | res = min(i * a + ((c / cp + (c % cp > 0)) * b), res); 14 | cp *= 2; 15 | } 16 | cout << res << "\n"; 17 | } 18 | 19 | signed main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int t = 1; 24 | cin >> t; 25 | while (t--) 26 | solve(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /CodeForces/GYM 564323 J. Resli utiful Pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define debug(x) cout << #x << " = "; cout << x << '\n'; 3 | using namespace std; 4 | typedef long long ll; 5 | const int ARRAY_SIZE = (int) 2e6+3; 6 | 7 | void idea() { 8 | ll n; 9 | cin >> n; 10 | ll x = n + 1; 11 | ll y = 2; 12 | cout << x << ' ' << y << '\n'; 13 | } 14 | 15 | int main() { 16 | ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 17 | int T = 1; 18 | cin >> T; 19 | for(int C = 1; C <= T; C++) { 20 | // cout << "Case " << C << ": " << '\n'; 21 | idea(); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 20-Word Count 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | char s[10001]; 7 | scanf(" %[^\n]", s); 8 | 9 | char* word; 10 | 11 | word = strtok(s, ",!;?. "); 12 | int counter=0; 13 | 14 | while(word!=NULL) 15 | { 16 | if (strlen(word) > 0) 17 | counter++; 18 | word = strtok(NULL, ",!;?. "); 19 | } 20 | cout << "Count = " << counter << '\n'; 21 | } 22 | 23 | int main(void) 24 | { 25 | int t; 26 | cin >> t; 27 | 28 | while(t--) 29 | { 30 | solve(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LeetCode/1047. Remove All Adjacent Duplicates In String.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeDuplicates(string s) { 4 | stack st; 5 | 6 | for (auto u: s) 7 | { 8 | if (st.empty()) st.push(u); 9 | else { 10 | if (st.top() == u) st.pop(); 11 | else st.push(u); 12 | } 13 | } 14 | 15 | string ans; 16 | while (!st.empty()) { 17 | ans.push_back(st.top()); 18 | st.pop(); 19 | } 20 | 21 | reverse(ans.begin(), ans.end()); 22 | return ans; 23 | } 24 | }; -------------------------------------------------------------------------------- /LeetCode/350. Intersection of Two Arrays II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector intersect(vector& nums1, vector& nums2) { 4 | sort(nums1.begin(), nums1.end()); 5 | sort(nums2.begin(), nums2.end()); 6 | vector ans; 7 | 8 | int i = 0, j = 0; 9 | while (i < nums1.size() and j < nums2.size()) { 10 | if (nums1[i] > nums2[j]) j++; 11 | else if (nums1[i] < nums2[j]) i++; 12 | else { 13 | ans.push_back(nums1[i]); 14 | i++, j++; 15 | } 16 | } 17 | 18 | return ans; 19 | } 20 | }; -------------------------------------------------------------------------------- /LeetCode/1317. Convert Integer to the Sum of Two No-Zero Integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkZero (int n) { 4 | while (n > 0) { 5 | if (n % 10 == 0) return true; 6 | n = n / 10; 7 | } 8 | return false; 9 | } 10 | 11 | vector getNoZeroIntegers(int n) { 12 | vector ans; 13 | for (int a = 1; a < n; a++) { 14 | int b = abs(a - n); 15 | 16 | if (!checkZero(a) and !checkZero(b)) { 17 | ans = {a, b}; 18 | break; 19 | } 20 | } 21 | 22 | return ans; 23 | } 24 | }; -------------------------------------------------------------------------------- /CodeForces/1579 A. Casimir's String Solitaire.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) 4 | { 5 | int t; 6 | scanf("%d", &t); 7 | while(t--) 8 | { 9 | int a_c=0, b=0, i; 10 | char str[50]; 11 | scanf(" %s", &str); 12 | int len = strlen(str); 13 | for(i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | string str; 6 | getline(cin, str); 7 | 8 | vector v; 9 | int x; 10 | 11 | for (int i=0; i 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | #define show(x) cout << #x << " : " << x << endl 6 | int main(void) 7 | { 8 | ll n; 9 | cin>>n; 10 | vector arr(n); 11 | for(ll i=0; i> arr[i]; 13 | 14 | ll min_mov=0, mov = 0; 15 | 16 | for(ll i=1; i 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | char ch; 7 | cin >> ch; 8 | 9 | if(ch>='a' && ch<='z') 10 | cout << "Lowercase character" << endl; 11 | else if(ch>='A' && ch<='Z') 12 | cout << "Uppercase character" << endl; 13 | else if(ch>='0' && ch<='9') 14 | cout << "Numerical Digit" << endl; 15 | else 16 | cout << "Special characters" << endl; 17 | } 18 | 19 | int main(void) 20 | { 21 | int t; 22 | cin>>t; 23 | while(t--) 24 | { 25 | solve(); 26 | } 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /LeetCode/3147. Taking Maximum Energy From the Mystic Dungeon.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumEnergy(vector& energy, int k) { 4 | int n = (int) energy.size(); 5 | 6 | vector vis(n, false); 7 | for (int i = n - k - 1; i >= 0; i--) { 8 | if (vis[i] == false) { 9 | int j = i; 10 | while (j >= 0) { 11 | vis[j] = true; 12 | energy[j] = energy[j] + energy[j + k]; 13 | j = j - k; 14 | } 15 | } 16 | } 17 | 18 | return *max_element(energy.begin(), energy.end()); 19 | } 20 | }; -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/4. Increasing Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | #define show(x) cout << #x << " : " << x << endl 6 | int main(void) 7 | { 8 | ll n; 9 | cin>>n; 10 | vector arr(n); 11 | for(ll i=0; i> arr[i]; 13 | 14 | ll min_mov=0, mov = 0; 15 | 16 | for(ll i=1; i= n) { 8 | if (i*i == n) sq = i; 9 | else sq = i - 1; 10 | break; 11 | } 12 | } 13 | 14 | int cnt = 0; 15 | for (int i = 1; i <= sq; i++) 16 | { 17 | if (n % i == 0) { 18 | if (n / i == i) cnt++; 19 | else cnt = cnt + 2; 20 | } 21 | } 22 | 23 | bool ans = (cnt == 3); 24 | 25 | return ans; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /CodeForces/304 A. Pythagorean Theorem II.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int mx = 1e8 + 123; 5 | bool perfect_squere[mx]; 6 | 7 | int main() 8 | { 9 | int n; cin >> n; 10 | int ans = 0; 11 | 12 | for (int i = 1; i <= n; i++) 13 | perfect_squere[i * i] = true; 14 | 15 | 16 | for (int a = 1; a <= n; a++) 17 | { 18 | for (int b = a; b <= n; b++) 19 | { 20 | int d = (a * a) + (b * b); 21 | if (d > n * n) break; 22 | if (perfect_squere[d] == true) 23 | ans++; 24 | } 25 | } 26 | 27 | cout << ans << endl; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /AIZU Online Judge/ITP1_6_D. Matrix Vector Multiplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a[123][123], b[123], c[123]; 7 | 8 | int n, m; cin >> n >> m; 9 | 10 | for (int i = 1; i <= n; i++) 11 | { 12 | for (int j = 1; j <= m; j++) 13 | cin >> a[i][j]; 14 | } 15 | 16 | for (int i = 1; i <= m; i++) cin >> b[i]; 17 | 18 | for (int k = 1; k <= n; k++) 19 | { 20 | c[k] = 0; 21 | for (int i = 1; i <= m; i++) 22 | { 23 | c[k] += (a[k][i] * b[i]); 24 | } 25 | cout << c[k] << endl; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /LeetCode/1935. Maximum Number of Words You Can Type.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int canBeTypedWords(string text, string brokenLetters) { 4 | vector brok(26, 0); 5 | for (auto &ch: brokenLetters) 6 | brok[ch - 'a'] = true; 7 | 8 | text += " "; 9 | int ans = 0; 10 | bool possible = true; 11 | for (auto &ch: text) { 12 | if (ch == ' ') { 13 | ans += ((possible == true) ? 1 : 0); 14 | possible = true; 15 | continue; 16 | } 17 | 18 | if (brok[ch - 'a']) possible = false; 19 | } 20 | 21 | return ans; 22 | } 23 | }; -------------------------------------------------------------------------------- /LeetCode/1304. Find N Unique Integers Sum up to Zero.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sumZero(int n) { 4 | if (n == 1) 5 | return {0}; 6 | if (n == 2) 7 | return {-1, 1}; 8 | if (n == 3) 9 | return {-1, 0, 1}; 10 | 11 | vector a(n, 0); 12 | 13 | if (n % 2 == 1) { 14 | a[0] = -1, a[1] = 0, a[2] = 1; 15 | for (int i = 3; i < n; i += 2) 16 | a[i] = i, a[i + 1] = (i * -1); 17 | } 18 | else { 19 | for (int i = 0; i < n; i += 2) 20 | a[i] = i + 1, a[i + 1] = ((i + 1) * -1); 21 | } 22 | 23 | return a; 24 | } 25 | }; -------------------------------------------------------------------------------- /LeetCode/2273. Find Resultant Array After Removing Anagrams.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector removeAnagrams(vector& words) { 4 | int n = (int) words.size(); 5 | 6 | vector ans; 7 | for (int i = 0; i < n; i++) { 8 | string x = words[i]; 9 | ans.push_back(x); 10 | sort(x.begin(), x.end()); 11 | 12 | for (int j = i + 1; j < n; j++) { 13 | string y = words[j]; 14 | sort(y.begin(), y.end()); 15 | 16 | if (x == y) {i = j; continue;} 17 | else break; 18 | } 19 | } 20 | 21 | return ans; 22 | } 23 | }; -------------------------------------------------------------------------------- /CodeForces/32 B. Borze.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | string borze_code; 7 | cin >> borze_code; 8 | 9 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | string str; 8 | cin >> str; 9 | 10 | int distinct = 0, flag = 0; 11 | for (int i=0; i 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | string line; 18 | cin >> line; 19 | 20 | if (isupper(line[0])) 21 | { 22 | cout << line << '\n'; 23 | } 24 | else 25 | { 26 | line[0] = line[0] - 32; 27 | cout << line << '\n'; 28 | } 29 | 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 2-Even-Odd 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int t; 8 | string number; 9 | 10 | cin >> t; 11 | 12 | while(t--) 13 | { 14 | cin >> number; 15 | 16 | int last_digit_asccii = (int) number[number.size()-1]; // Type casting from character to int returns ASCII value 17 | int last_digit = last_digit_asccii - 48; // ASCII value of 0-9 is 48-57 18 | 19 | if (last_digit >= 0 && last_digit <= 9) 20 | { 21 | if(last_digit%2 == 0) 22 | cout << "even" << endl; 23 | else 24 | cout << "odd" << endl; 25 | } 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /LeetCode/128. Longest Consecutive Sequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestConsecutive(vector& nums) { 4 | if (nums.size() == 0) return 0; 5 | 6 | unordered_set st; 7 | for (auto &&u: nums) st.insert(u); 8 | 9 | int longest = 1; 10 | for (auto &&u: st) { 11 | if (st.find(u - 1) == st.end()) { 12 | int consecutive = 1; 13 | int next = u + 1; 14 | while (st.find(next) != st.end()) { 15 | consecutive++; 16 | next++; 17 | } 18 | 19 | longest = max(longest, consecutive); 20 | } 21 | } 22 | 23 | return longest; 24 | } 25 | }; -------------------------------------------------------------------------------- /CodeChef/START105C - C. Dull Operation.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | #define endl '\n' 7 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 8 | 9 | /*---------------------------------------------------------------------------------------------------------------*/ 10 | 11 | void solve() 12 | { 13 | int n; cin >> n; 14 | cout << n << " " << n - 1 << endl; 15 | } 16 | 17 | int main(void) 18 | { 19 | efficient(); 20 | 21 | int t = 1; 22 | cin >> t; 23 | for (int tc = 1; tc <= t; tc++) 24 | { 25 | // cout << "Case " << tc << ": "; 26 | solve(); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /LeetCode/2379. Minimum Recolors to Get K Consecutive Black Blocks.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumRecolors(string blocks, int k) { 4 | 5 | int l = 0, r = k - 1; 6 | int white = 0, black = 0; 7 | 8 | for (int i = 0; i < k; i++) { 9 | if (blocks[i] == 'B') black++; 10 | else white++; 11 | } 12 | 13 | int ans = white; 14 | while (r < (int) blocks.size()) { 15 | if (blocks[l] == 'B') black--; 16 | else white--; 17 | l++, r++; 18 | if (blocks[r] == 'B') black++; 19 | else white++; 20 | 21 | ans = min(white, ans); 22 | } 23 | 24 | return ans; 25 | } 26 | }; -------------------------------------------------------------------------------- /CodeForces/112 A. Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | string str1, str2; 8 | cin >> str1 >> str2; 9 | 10 | int res; 11 | 12 | transform(str1.begin(), str1.end(), str1.begin(), ::tolower); 13 | transform(str2.begin(), str2.end(), str2.begin(), ::tolower); 14 | 15 | for(int i=0; i str2[i]) 18 | { 19 | res = 1; 20 | break; 21 | } 22 | else if (str1[i] < str2[i]) 23 | { 24 | res = -1; 25 | break; 26 | } 27 | else 28 | res = 0; 29 | } 30 | 31 | cout << res << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 27-Armstrong Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int temp = n, res = 0; 10 | 11 | while(temp!=0) 12 | { 13 | int reminder = temp%10; 14 | res = res + (reminder * reminder * reminder); 15 | temp = temp / 10; 16 | } 17 | 18 | if (n == res) 19 | { 20 | cout << n << " is an armstrong number!" << endl; 21 | } 22 | else 23 | { 24 | cout << n << " is not an armstrong number!" << endl; 25 | } 26 | } 27 | 28 | int main(void) 29 | { 30 | int t=1; 31 | cin>>t; 32 | while(t--) 33 | { 34 | solve(); 35 | } 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 23-Letter to Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /* 5 | void solve() 6 | { 7 | string line; 8 | cin >> line; 9 | 10 | for (int i=0; i= 'A' && line[i] <= 'Z') 13 | { 14 | cout << line[i]-64; 15 | } 16 | } 17 | cout << endl; 18 | } 19 | */ 20 | void solve() 21 | { 22 | string line; 23 | cin >> line; 24 | 25 | for (int i=0; i>t; 36 | while(t--) 37 | { 38 | solve(); 39 | } 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /CodeForces/GYM 564323 L. Ammar utiful Permutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define debug(x) cout << #x << " = "; cout << x << '\n'; 3 | using namespace std; 4 | typedef long long ll; 5 | const int ARRAY_SIZE = (int) 2e6+3; 6 | 7 | void idea() { 8 | int n; 9 | cin >> n; 10 | if(n == 2) { 11 | cout << "1 2" << '\n'; 12 | return; 13 | } 14 | for(int i = 1; i <= n; i+= 2) cout << i << ' '; 15 | for(int i = 2; i <= n; i+= 2) cout << i << ' '; 16 | cout << '\n'; 17 | } 18 | 19 | int main() { 20 | ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 21 | int T = 1; 22 | cin >> T; 23 | for(int C = 1; C <= T; C++) { 24 | // cout << "Case " << C << ": " << '\n'; 25 | idea(); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /LeetCode/118. Pascal's Triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> generate(int numRows) { 4 | vector> pascal; 5 | 6 | pascal.push_back({1}); 7 | if (numRows == 1) return pascal; 8 | 9 | pascal.push_back({1, 1}); 10 | if (numRows == 2) return pascal; 11 | 12 | for (int i = 2; i < numRows; i++) { 13 | vector vec; 14 | vec.push_back(1); 15 | 16 | for (int j = 1; j < (int) pascal[i - 1].size(); j++) 17 | vec.push_back( pascal[i - 1][j - 1] + pascal[i - 1][j] ); 18 | 19 | vec.push_back(1); 20 | 21 | pascal.push_back(vec); 22 | } 23 | 24 | return pascal; 25 | } 26 | }; -------------------------------------------------------------------------------- /LeetCode/35. Search Insert Position.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& nums, int target) { 4 | int n = nums.size(); 5 | int l = 0, r = n - 1, lowerBound = n; 6 | 7 | while (l <= r) { 8 | int mid = l + (r - l) / 2; 9 | 10 | if (nums[mid] >= target) { 11 | // lowerBound = mid; 12 | // Or, 13 | lowerBound = min(lowerBound, mid); 14 | r = mid - 1; 15 | } 16 | else l = mid + 1; 17 | } 18 | 19 | // Another Solution 20 | // int lowerBound = (lower_bound(nums.begin(), nums.end(), target)) - nums.begin(); 21 | // On runtime -> Beats 100.00% of users with C++ 22 | 23 | return lowerBound; 24 | } 25 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 14-Character Frequency.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int kount = 0; 7 | char line[10001]; 8 | char ch[2]; 9 | 10 | scanf(" %[^\n]", line); 11 | scanf("%s", ch); 12 | 13 | for (int i=0; i= 0LL) 9 | { 10 | n = n - (val * val_digit); 11 | val = val * 10; 12 | val_digit++; 13 | } 14 | 15 | long long start = val / 9LL; 16 | start = start + (n / val_digit); 17 | 18 | if (n % val_digit == 0LL) { 19 | start--; 20 | return start % 10LL; 21 | } 22 | else { 23 | int id = n % val_digit; 24 | string num = to_string(start); 25 | return num[id - 1] - '0'; 26 | } 27 | } 28 | }; -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 8-Small to Large.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void swaping(int *xp, int *yp) 5 | { 6 | int temp = *xp; 7 | *xp = *yp; 8 | *yp = temp; 9 | } 10 | 11 | int main(void) 12 | { 13 | int t; 14 | cin >> t; 15 | 16 | for (int i=1; i<=t; i++) 17 | { 18 | int n1, n2, n3, temp; 19 | cin >> n1 >> n2 >> n3; 20 | 21 | if(n1 > n2) 22 | { 23 | swaping(&n1, &n2); 24 | } 25 | 26 | if(n2 > n3) 27 | { 28 | swaping(&n2, &n3); 29 | } 30 | 31 | if(n1 > n2) 32 | { 33 | swaping(&n1, &n2); 34 | } 35 | 36 | cout << "Case " << i << ": " << n1 << ' ' << n2 << ' ' << n3 << endl; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /LeetCode/3349. Adjacent Increasing Subarrays Detection I.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | bool check (vector& nums, int start, int end) { 3 | bool ans = true; 4 | 5 | for (int i = start + 1; i <= end; i++) 6 | if (nums[i - 1] >= nums[i]) 7 | ans = false; 8 | 9 | return ans; 10 | } 11 | 12 | public: 13 | bool hasIncreasingSubarrays(vector& nums, int k) { 14 | int n = (int) nums.size(); 15 | 16 | for (int i = 0; i + (2 * k - 1) < n; i++) { 17 | bool first = check(nums, i, i + k - 1); 18 | bool second = check(nums, i + k, i + 2 * k - 1); 19 | 20 | if (first && second) { 21 | return true; 22 | } 23 | } 24 | 25 | return false; 26 | } 27 | }; -------------------------------------------------------------------------------- /CodeForces/266 B. Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int char_len, second; 7 | cin >> char_len >> second; 8 | 9 | char line[char_len]; 10 | for (int i=0; i> line[i]; 12 | 13 | for (int i=1; i<=second; i++) 14 | { 15 | int index = 0; 16 | while (index <= char_len-1) 17 | { 18 | if(line[index]=='B' && line[index+1]=='G') 19 | { 20 | swap(line[index], line[index+1]); 21 | index = index + 2; 22 | } 23 | else 24 | index++; 25 | } 26 | 27 | } 28 | for (int i=0; i 3 | using namespace std; 4 | 5 | #define endl '\n' 6 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 7 | 8 | void solve() 9 | { 10 | int n; cin >> n; 11 | 12 | map freq; 13 | while (n--) 14 | { 15 | string s; cin >> s; 16 | 17 | if (freq[s] == 0) cout << "OK" << endl; 18 | else cout << s << freq[s] << endl; 19 | 20 | freq[s]++; 21 | } 22 | 23 | } 24 | 25 | int main(void) 26 | { 27 | efficient(); 28 | 29 | int t = 1; 30 | // cin >> t; 31 | for (int tc = 1; tc <= t; tc++) 32 | { 33 | // cout << "Case " << tc << ": "; 34 | solve(); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Sum of large numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string add(string s1, string s2) { 4 | reverse(s1.begin(), s1.end()); 5 | reverse(s2.begin(), s2.end()); 6 | 7 | string sum = ""; 8 | 9 | int i = 0, j = 0, c = 0; 10 | while (true) { 11 | int a = 0, b = 0; 12 | 13 | if (i < (int) s1.size()) a = s1[i] - '0', i++; 14 | if (j < (int) s2.size()) b = s2[j] - '0', j++; 15 | 16 | int s = (a + b + c) % 10; 17 | c = (a + b + c) / 10; 18 | 19 | sum.push_back( s + '0' ); 20 | 21 | if (i == (int) s1.size() and j == (int) s2.size() and c == 0) 22 | break; 23 | } 24 | 25 | reverse(sum.begin(), sum.end()); 26 | return sum; 27 | } 28 | }; -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Queue Push & Pop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | queue_push(int arr[],int n); 5 | 6 | 7 | void _pop(queues); 8 | 9 | 10 | queue_push(int arr[],int n) 11 | { 12 | queue q; 13 | for (int i = 0; i < n; i++) 14 | q.push(arr[i]); 15 | 16 | return q; 17 | } 18 | 19 | void _pop(queues) 20 | { 21 | while(!s.empty()) { 22 | cout << s.front() << " "; 23 | s.pop(); 24 | } 25 | } 26 | 27 | 28 | int main() { 29 | int t; 30 | cin>>t; 31 | while(t--) 32 | { 33 | int n; 34 | cin>>n; 35 | int arr[n]; 36 | for(int i=0;i>arr[i]; 38 | queuemys =_push(arr,n); 39 | _pop(mys); 40 | cout< vis; 4 | vector> adj; 5 | 6 | void dfs (int node) { 7 | vis[node] = true; 8 | 9 | for (auto u: adj[node]) { 10 | if (vis[u] == false) 11 | dfs(u); 12 | } 13 | return; 14 | } 15 | bool validPath(int n, vector>& edges, int source, int destination) { 16 | int mx = 2e5 + 123; 17 | vis.resize(mx); adj.resize(mx); 18 | 19 | for (auto &e: edges) { 20 | int u = e[0], v = e[1]; 21 | 22 | adj[u].push_back(v); 23 | adj[v].push_back(u); 24 | } 25 | 26 | dfs(source); 27 | 28 | if (vis[destination]) return true; 29 | else return false; 30 | } 31 | }; -------------------------------------------------------------------------------- /LeetCode/1437. Check If All 1's Are at Least Length K Places Away.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool kLengthApart(vector& nums, int k) { 4 | int n = (int) nums.size(); 5 | 6 | for (int i = 0; i < n; i++) { 7 | if (nums[i] == 1) { 8 | int cnt_zero = 0; 9 | for (int j = i + 1; j < n; j++) { 10 | if (nums[j] == 0) cnt_zero++; 11 | else { 12 | if (cnt_zero >= k) { 13 | cnt_zero = 0; 14 | i = j - 1; 15 | break; 16 | } 17 | else return false; 18 | } 19 | } 20 | } 21 | } 22 | 23 | return true; 24 | } 25 | }; -------------------------------------------------------------------------------- /CodeForces/GYM 102141 G. Decode The Alien Message.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define efficient() \ 5 | ios_base::sync_with_stdio(0); \ 6 | cin.tie(0); 7 | 8 | void solve(void) 9 | { 10 | int n; 11 | cin>>n; 12 | vectorv(n); 13 | for(int i = 0; i < n; i++) { 14 | int x; 15 | cin >> x; 16 | x %= 2; 17 | x ^= 1; 18 | v[i] = x; 19 | } 20 | int j = 0; 21 | while(v[j] == 0)j++; 22 | for(int i = j; i < n; i++) cout << v[i]; 23 | cout << "\n"; 24 | } 25 | 26 | signed main() 27 | { 28 | efficient(); 29 | int t = 1, Test; 30 | cin >> t; 31 | for (Test = 1; Test <= t; Test++) 32 | { 33 | cout << "Case " << Test << ": "; 34 | solve(); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /LeetCode/415. Add Strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string addStrings(string num1, string num2) { 4 | reverse(num1.begin(), num1.end()); 5 | reverse(num2.begin(), num2.end()); 6 | 7 | string sum = ""; 8 | 9 | int i = 0, j = 0, c = 0; 10 | while (true) { 11 | int a = 0, b = 0; 12 | 13 | if (i < (int) num1.size()) a = num1[i] - '0', i++; 14 | if (j < (int) num2.size()) b = num2[j] - '0', j++; 15 | 16 | int s = (a + b + c) % 10; 17 | c = (a + b + c) / 10; 18 | 19 | sum.push_back( s + '0' ); 20 | 21 | if (i == (int) num1.size() and j == (int) num2.size() and c == 0) 22 | break; 23 | } 24 | 25 | reverse(sum.begin(), sum.end()); 26 | return sum; 27 | } 28 | }; -------------------------------------------------------------------------------- /CodeForces/110 A. Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | ll number; 18 | int kount = 0; 19 | 20 | cin >> number; 21 | 22 | while(number!=0) 23 | { 24 | if (number%10 == 7 || number%10 == 4) 25 | kount++; 26 | number = number/10; 27 | } 28 | 29 | if (kount == 4 || kount == 7) 30 | cout << "YES" << '\n'; 31 | else 32 | cout << "NO" << '\n'; 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /LeetCode/2300. Successful Pairs of Spells and Potions.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector successfulPairs(vector& spells, vector& potions, long long success) { 4 | int n = (int) spells.size(); 5 | int m = (int) potions.size(); 6 | 7 | sort(potions.begin(), potions.end()); 8 | vector ans; 9 | for (long long u: spells) { 10 | int l = 0, r = m - 1, idx = -1; 11 | while (l <= r) { 12 | int mid = l + (r - l) / 2; 13 | if (u * potions[mid] >= success) { 14 | idx = mid; 15 | r = mid - 1; 16 | } 17 | else l = mid + 1; 18 | } 19 | ans.push_back( (idx == -1 ? 0 : m - idx) ); 20 | } 21 | 22 | return ans; 23 | } 24 | }; -------------------------------------------------------------------------------- /CodeForces/1765 B. Broken Keyboard.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | void solve() 5 | { 6 | int n; 7 | cin>>n; 8 | string s; 9 | cin>>s; 10 | for(int i=0; i>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /CodeForces/GYM 556326 E. Fatigue-Fighting Vacation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | void Approach(){ 6 | ll n, a, b; 7 | cin >> n >> a >> b; 8 | vector x(a), y(b); 9 | 10 | for(auto &ii : x){ 11 | cin >> ii; 12 | } 13 | for(auto &ii : y){ 14 | cin >> ii; 15 | n += ii; 16 | } 17 | 18 | ll ans = b; 19 | 20 | for (int i = 0; i < a; i++) { 21 | if (n >= x[i]) { 22 | ans++; 23 | n -= x[i]; 24 | } 25 | else break; 26 | } 27 | 28 | cout << ans << '\n'; 29 | } 30 | 31 | int main(){ 32 | ios::sync_with_stdio(0); 33 | cin.tie(0); cout.tie(0); 34 | 35 | ll T = 1; 36 | //cin >> T; 37 | for(ll C = 1; C <= T; C++){ 38 | Approach(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /LeetCode/2327. Number of People Aware of a Secret.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mod = 1e9 + 7; 4 | int peopleAwareOfSecret(int n, int delay, int forget) { 5 | vector a(n + 1, 0); 6 | a[1] = 1; 7 | 8 | for (int i = 1; i <= n; i++) { 9 | if (a[i] > 0) { 10 | int l = i + delay; 11 | int r = i + forget; 12 | 13 | while (l < min(r, n + 1)) { 14 | a[l] = ((a[l] % mod) + (a[i] % mod)) % mod; 15 | l++; 16 | } 17 | if (r <= n) 18 | a[i] = 0; 19 | } 20 | } 21 | 22 | int ans = 0; 23 | for (int i = 1; i <= n; i++) { 24 | ans = ((ans % mod) + (a[i] % mod)) % mod; 25 | } 26 | 27 | return ans; 28 | } 29 | }; -------------------------------------------------------------------------------- /LeetCode/20. Valid Parentheses.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isValid(string s) { 4 | stack stk; 5 | for (auto u: s) { 6 | if (stk.empty()) 7 | stk.push(u); 8 | else if (u == '(' || u == '{' || u == '[') 9 | stk.push(u); 10 | else if (u == ')') { 11 | if (stk.top() == '(') stk.pop(); 12 | else stk.push(u); 13 | } 14 | else if (u == '}') { 15 | if (stk.top() == '{') stk.pop(); 16 | else stk.push(u); 17 | } 18 | else if (u == ']') { 19 | if (stk.top() == '[') stk.pop(); 20 | else stk.push(u); 21 | } 22 | } 23 | 24 | if (stk.empty()) return true; 25 | else return false; 26 | } 27 | }; -------------------------------------------------------------------------------- /CodeForces/1512 A. Spy Detected!.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int t; 5 | scanf("%d", &t); 6 | while (t--) 7 | { 8 | int size, i, j, count; 9 | scanf("%d", &size); 10 | int arr1[size], arr2[size]; 11 | for (i=0; i 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define show(x) cout << #x << " : " << x << endl 11 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 12 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 13 | 14 | void solve() 15 | { 16 | ll n; 17 | cin >> n; 18 | if (n%2 == 0) 19 | { 20 | cout << ll(n/2) << endl; 21 | return; 22 | } 23 | else 24 | cout << ll((n/2)+1) << endl; 25 | } 26 | 27 | int main(void) 28 | { 29 | //efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /CodeForces/1743 A. Password.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define show(x) cout << #x << " : " << x << endl 11 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 12 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 13 | 14 | void solve() 15 | { 16 | int n; cin >> n; 17 | int arr[n]; 18 | for (int i=0; i> arr[i]; 20 | 21 | n = 10-n-1; 22 | 23 | int sum = (n*(n+1)/2); 24 | 25 | cout << sum*6 << endl; 26 | } 27 | 28 | int main(void) 29 | { 30 | efficient; 31 | 32 | int t=1; 33 | cin>>t; 34 | while(t--) 35 | { 36 | solve(); 37 | } 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /CodeForces/1750 A. Indirect Sort.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define show(x) cout << #x << " : " << x << endl 11 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 12 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 13 | 14 | void solve() 15 | { 16 | int n; cin >> n; 17 | int arr[n]; 18 | for (int i=0; i> arr[i]; 20 | 21 | if(arr[0] == 1) 22 | cout << "YES" << endl; 23 | else 24 | cout << "NO" << endl; 25 | } 26 | 27 | int main(void) 28 | { 29 | //efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 22-Prime Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define size 100001 5 | int ara[size]; 6 | 7 | void SieveOfEratosthenes() 8 | { 9 | int i, j, root; 10 | for (i=2; i> t; 30 | while(t--) 31 | { 32 | cin >> a >> b; 33 | count = 0; 34 | 35 | for (int i=a; i<=b; i++) 36 | { 37 | if (ara[i]) 38 | count++; 39 | } 40 | cout << count << '\n'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CodeForces/266 A. Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | int length, counter=0; 18 | cin >> length; 19 | 20 | char s[length]; 21 | cin >> s; 22 | 23 | char target = s[0]; 24 | for (int i=0; i 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | ll n, s1=0, s2=0, x; 16 | cin >> n; 17 | 18 | for (ll i=1; i<=n; i++) 19 | { 20 | cin >> x; 21 | if(x<=0) 22 | s1 += abs(x); 23 | else 24 | s2 += x; 25 | } 26 | 27 | cout << abs(s1-s2) << endl; 28 | } 29 | 30 | int main(void) 31 | { 32 | efficient; 33 | 34 | int t=1; 35 | cin>>t; 36 | while(t--) 37 | { 38 | solve(); 39 | } 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /CodeForces/GYM 556326 I. Lexicographical Challenge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | void Approach(){ 6 | string s; 7 | cin >> s; 8 | 9 | ll k; 10 | cin >> k; 11 | 12 | ll n = s.size(); 13 | 14 | for(ll ii = 0; ii < k; ii++){ 15 | string t; 16 | t.clear(); 17 | for(ll jj = ii; jj < n; jj += k){ 18 | t.push_back(s[jj]); 19 | } 20 | sort(t.begin(), t.end()); 21 | 22 | for(ll jj = ii, kk = 0; jj < n; jj += k, kk++){ 23 | s[jj] = t[kk]; 24 | } 25 | 26 | } 27 | 28 | 29 | cout << s << "\n"; 30 | } 31 | 32 | int main(){ 33 | ios::sync_with_stdio(0); 34 | cin.tie(0); cout.tie(0); 35 | 36 | ll T = 1; 37 | //cin >> T; 38 | for(ll C = 1; C <= T; C++){ 39 | Approach(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /CodeForces/1742 A. Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int a, b, c; 16 | cin >> a >> b >> c; 17 | if (a == b+c) 18 | cout << "YES" << '\n'; 19 | else if (b == a+c) 20 | cout << "YES" << '\n'; 21 | else if (c == a+b) 22 | cout << "YES" << '\n'; 23 | else 24 | cout << "NO" << '\n'; 25 | } 26 | 27 | int main(void) 28 | { 29 | efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /HackerEarth/Monk_s_Encounter_with_Polynomial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | 6 | void solve() 7 | { 8 | ll a, b, c, k; cin >> a >> b >> c >> k; 9 | ll l = 0, r = 100000; 10 | ll x = 100000; 11 | 12 | while (l <= r) { 13 | ll mid = l + (r - l) / 2LL; 14 | ll val = (a * mid * mid) + (b * mid) + c; 15 | 16 | if (val == k) { 17 | x = mid; 18 | break; 19 | } 20 | else if (val < k) l = mid + 1; 21 | else { 22 | r = mid - 1; 23 | x = min(x, mid); 24 | } 25 | } 26 | 27 | cout << x << endl; 28 | } 29 | 30 | int main() 31 | { 32 | ios_base::sync_with_stdio(0); 33 | cin.tie(0); 34 | 35 | int t; 36 | cin >> t; 37 | while (t--) 38 | { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /CodeForces/1660 B. Vlad and Candies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | 4 | using namespace std; 5 | 6 | int main(void) 7 | { 8 | ll t; 9 | cin >> t; 10 | 11 | while(t--) 12 | { 13 | ll type; 14 | cin >> type; 15 | 16 | ll arr[type]; 17 | 18 | for (ll i=0; i> arr[i]; 20 | 21 | ll n = sizeof(arr) / sizeof(arr[0]); 22 | 23 | if (type == 1) 24 | { 25 | if (arr[0] > 1) 26 | cout << "NO" << endl; 27 | else 28 | cout << "YES" << endl; 29 | 30 | continue; 31 | } 32 | 33 | sort(arr, arr + n); 34 | 35 | 36 | if (arr[n-1] - arr[n-2] > 1) 37 | cout << "NO" << endl; 38 | else 39 | cout << "YES" << endl; 40 | 41 | 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /SPOJ/BSEARCH1 - Binary search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Use '\n' or you will get TLE 5 | #define endl '\n' 6 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 7 | const int mx = 1e5 + 123; 8 | int a[mx]; 9 | 10 | int main() 11 | { 12 | efficient(); 13 | int n, q; cin >> n >> q; 14 | for (int i = 0; i < n; i++) cin >> a[i]; 15 | 16 | while (q--) { 17 | int target; cin >> target; 18 | int l = 0, r = n - 1, ans = n; 19 | 20 | while (l <= r) 21 | { 22 | int mid = l + (r - l) / 2; 23 | 24 | if (a[mid] == target) ans = min(ans, mid); 25 | if (a[mid] >= target) r = mid - 1; 26 | else l = mid + 1; 27 | } 28 | 29 | if (ans == n) ans = -1; 30 | 31 | cout << ans << endl; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /LeetCode/1488. Avoid Flood in The City.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector avoidFlood(vector& rains) { 4 | int n = (int) rains.size(); 5 | 6 | unordered_map fill; 7 | set zero; 8 | vector ans(n, 1); 9 | 10 | for (int i = 0; i < n; i++) { 11 | int lake = rains[i]; 12 | if (lake == 0) { 13 | zero.insert(i); 14 | } 15 | else { 16 | if (fill.count(lake)) { 17 | auto it = zero.lower_bound(fill[lake]); 18 | if (it == zero.end()) return {}; 19 | 20 | ans[*it] = lake; 21 | zero.erase(it); 22 | } 23 | 24 | ans[i] = -1; 25 | fill[lake] = i; 26 | } 27 | } 28 | 29 | return ans; 30 | } 31 | }; -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Queue Reversal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution 5 | { 6 | public: 7 | queue rev(queue q) 8 | { 9 | stack st; 10 | while(!q.empty()) { 11 | st.push(q.front()); 12 | q.pop(); 13 | } 14 | while(!st.empty()) { 15 | q.push(st.top()); 16 | st.pop(); 17 | } 18 | return q; 19 | } 20 | }; 21 | 22 | int main() 23 | { 24 | int test; 25 | cin>>test; 26 | while(test--) 27 | { 28 | queue q; 29 | int n, var; 30 | cin>>n; 31 | while(n--) 32 | { 33 | cin>>var; 34 | q.push(var); 35 | } 36 | Solution ob; 37 | queue a=ob.rev(q); 38 | while(!a.empty()) 39 | { 40 | cout< 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | string grid[8]; 16 | for (int i=0; i<8; i++) 17 | cin >> grid[i]; 18 | 19 | 20 | for (int i=0; i<8; i++) 21 | { 22 | if(grid[i] == "RRRRRRRR") 23 | { 24 | cout << 'R' << '\n'; 25 | return; 26 | } 27 | } 28 | cout << 'B' << '\n'; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /CodeForces/1761 A. Two Permutations.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n, a, b; 19 | cin >> n >> a >> b; 20 | 21 | if (n==a and a==b) yes; 22 | else if (a+b < n-1) yes; 23 | else no; 24 | } 25 | 26 | int main(void) 27 | { 28 | efficient; 29 | 30 | int t=1; 31 | cin>>t; 32 | while(t--) 33 | { 34 | solve(); 35 | } 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /CodeForces/GYM 556326 H. Investigating Zeroes and Ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | 6 | 7 | ll count(vector &a, ll n){ 8 | 9 | ll temp[2] = {1, 0}; 10 | ll result = 0, val = 0; 11 | 12 | for (ll i = 0; i + 1 <= n; i++) { 13 | 14 | val = ((val + a[i]) % 2 + 2) % 2; 15 | 16 | temp[val]++; 17 | } 18 | 19 | result = (temp[0] * temp[1]); 20 | return (result); 21 | 22 | } 23 | void Approach(){ 24 | ll n; 25 | cin >> n; 26 | vector a(n); 27 | for(ll &ii : a){ 28 | cin >> ii; 29 | } 30 | 31 | ll ans = count(a, n); 32 | 33 | cout << ans << '\n'; 34 | } 35 | 36 | int main(){ 37 | ios::sync_with_stdio(0); 38 | cin.tie(0); cout.tie(0); 39 | 40 | ll T = 1; 41 | //cin >> T; 42 | for(ll C = 1; C <= T; C++){ 43 | Approach(); 44 | } 45 | return 0; 46 | } -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Twice Counter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution 5 | { 6 | public: 7 | int countWords(string list[], int n) 8 | { 9 | map freq; 10 | 11 | for(int i = 0; i < n; i++) { 12 | string s = list[i]; 13 | freq[s]++; 14 | } 15 | 16 | int ans = 0; 17 | for(auto u: freq) { 18 | if (u.second == 2) ans++; 19 | } 20 | 21 | return ans; 22 | } 23 | }; 24 | 25 | int main() 26 | { 27 | int t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | int n; 32 | cin>>n; 33 | string list[n]; 34 | for(int i=0;i>list[i]; 36 | Solution ob; 37 | cout < 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | string s, r; 19 | cin >> s; 20 | 21 | r = s; 22 | reverse(r.begin(), r.end()); 23 | 24 | cout << s << r << endl; 25 | } 26 | 27 | int main(void) 28 | { 29 | //efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /CodeForces/1760 A. Medium Number.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int arr[3]; 19 | for (int i=0; i<3; i++) 20 | cin >> arr[i]; 21 | 22 | sort(arr, arr+3); 23 | 24 | cout << arr[1] << endl; 25 | } 26 | 27 | int main(void) 28 | { 29 | efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1083 - Missing Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int n; 7 | cin >> n; 8 | int arr[n-1]; 9 | 10 | for (int i=0; i> arr[i]; 12 | 13 | sort(arr, arr + n-1); 14 | 15 | for (int i=1; i<=n; i++) 16 | { 17 | if(!binary_search(arr, arr + n - 1 , i)) 18 | cout << i << '\n'; 19 | } 20 | 21 | } 22 | 23 | // Another Way to solve this problem 24 | // 1+2+3+.....+n = n * (n + 1) ) / 2 25 | // property of the natural numbers 26 | /* 27 | #include 28 | using namespace std; 29 | 30 | int main() { 31 | long long int n, input, sum = 0; 32 | cin >> n; 33 | 34 | for (int i = 0 ; i < n - 1 ; i++) { 35 | cin >> input; 36 | sum += input; 37 | } 38 | 39 | cout << ( n * (n + 1) ) / 2 - sum << endl; 40 | 41 | return 0; 42 | } 43 | */ 44 | -------------------------------------------------------------------------------- /CodeForces/1553 A. Digits Sum.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll n, ans = 0; 19 | cin >> n; 20 | 21 | 22 | ans = n / 10; 23 | 24 | if (n%10 == 9) 25 | ans++; 26 | 27 | cout << ans << endl; 28 | } 29 | 30 | int main(void) 31 | { 32 | efficient; 33 | 34 | int t=1; 35 | cin>>t; 36 | while(t--) 37 | { 38 | solve(); 39 | } 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /CodeForces/22 A. Second Order Statistics.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef unsigned long long ull; 7 | 8 | #define endl '\n' 9 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 10 | #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); 11 | 12 | /*---------------------------------------------------------------------------------------------------------------*/ 13 | 14 | int main(void) 15 | { 16 | efficient(); 17 | 18 | set s; 19 | int n; cin >> n; 20 | for (int i = 0; i < n; i++) 21 | { 22 | int x; cin >> x; 23 | s.insert(x); 24 | } 25 | 26 | if (s.size() == 1) cout << "NO" << endl; 27 | else { 28 | cout << *(++s.begin()) << endl; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /LeetCode/349. Intersection of Two Arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector intersection(vector& nums1, vector& nums2) { 4 | sort(nums1.begin(), nums1.end()); 5 | sort(nums2.begin(), nums2.end()); 6 | vector ans; 7 | int prev = -1; 8 | 9 | for (auto u: nums1) { 10 | if (prev == u) continue; 11 | prev = u; 12 | 13 | bool isExists = false; 14 | int l = 0, r = nums2.size() - 1; 15 | while(l <= r) { 16 | int mid = l + (r - l) / 2; 17 | if (nums2[mid] == u) { 18 | isExists = true; 19 | break; 20 | } 21 | else if (nums2[mid] < u) l = mid + 1; 22 | else r = mid - 1; 23 | } 24 | 25 | if (isExists) ans.push_back(u); 26 | } 27 | 28 | return ans; 29 | } 30 | }; -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/2. Missing Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | int n; 7 | cin >> n; 8 | int arr[n-1]; 9 | 10 | for (int i=0; i> arr[i]; 12 | 13 | sort(arr, arr + n-1); 14 | 15 | for (int i=1; i<=n; i++) 16 | { 17 | if(!binary_search(arr, arr + n - 1 , i)) 18 | cout << i << '\n'; 19 | } 20 | 21 | } 22 | 23 | // Another Way to solve this problem 24 | // 1+2+3+.....+n = n * (n + 1) ) / 2 25 | // property of the natural numbers 26 | /* 27 | #include 28 | using namespace std; 29 | 30 | int main() { 31 | long long int n, input, sum = 0; 32 | cin >> n; 33 | 34 | for (int i = 0 ; i < n - 1 ; i++) { 35 | cin >> input; 36 | sum += input; 37 | } 38 | 39 | cout << ( n * (n + 1) ) / 2 - sum << endl; 40 | 41 | return 0; 42 | } 43 | */ 44 | -------------------------------------------------------------------------------- /AIZU Online Judge/ITP1_3_D. How Many Divisors.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | int main(void) 6 | { 7 | int a, b, c; 8 | cin >> a >> b >> c; 9 | 10 | int sq; 11 | for (int i = 1; i <= c; i++) 12 | { 13 | if (i * i >= c) 14 | { 15 | if (i * i == c) 16 | sq = i; 17 | else 18 | sq = i - 1; 19 | break; 20 | } 21 | } 22 | 23 | int ans = 0; 24 | for (int i = 1; i <= sq; i++) 25 | { 26 | if (c % i == 0) 27 | { 28 | if (i >= a && i <= b) 29 | ans++; 30 | if (c / i != i) 31 | { 32 | int d = c / i; 33 | if (d >= a && d <= b) 34 | ans++; 35 | } 36 | } 37 | } 38 | 39 | cout << ans << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /CodeForces/1669 A. Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n; 16 | cin >> n; 17 | 18 | if (n >= 1900) 19 | cout << "Division 1" << endl; 20 | else if (n >= 1600 && n<= 1899) 21 | cout << "Division 2" << endl; 22 | else if (n >= 1400 && n<=1599) 23 | cout << "Division 3" << endl; 24 | else 25 | cout << "Division 4" << endl; 26 | 27 | } 28 | 29 | int main(void) 30 | { 31 | efficient; 32 | 33 | int t=1; 34 | cin>>t; 35 | while(t--) 36 | { 37 | solve(); 38 | } 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /CodeForces/1760 B. Atilla's Favorite Problem.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; cin >> n; 19 | char str[n]; 20 | 21 | cin >> str; 22 | 23 | sort(str, str+n); 24 | 25 | cout << int(str[n-1]-96) << endl; 26 | } 27 | 28 | int main(void) 29 | { 30 | efficient; 31 | 32 | int t=1; 33 | cin>>t; 34 | while(t--) 35 | { 36 | solve(); 37 | } 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /LeetCode/812. Largest Triangle Area.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double largestTriangleArea(vector>& points) { 4 | int n = points.size(); 5 | double ans = 0.00; 6 | 7 | for (int i = 0; i + 2 < n; i++) { 8 | int x1 = points[i][0]; 9 | int y1 = points[i][1]; 10 | 11 | for (int j = i + 1; j + 1 < n; j++) { 12 | int x2 = points[j][0]; 13 | int y2 = points[j][1]; 14 | 15 | for (int k = j + 1; k < n; k++) { 16 | int x3 = points[k][0]; 17 | int y3 = points[k][1]; 18 | 19 | // Area of a triangle with points 20 | double area = 0.5 * abs((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))); 21 | 22 | ans = max(ans, area); 23 | } 24 | } 25 | } 26 | 27 | return ans; 28 | } 29 | }; -------------------------------------------------------------------------------- /CodeForces/1729 A. Two Elevators.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | void solve() 13 | { 14 | ll a, b, c; 15 | cin >> a >> b >> c; 16 | 17 | ll f_ele = a-1; 18 | ll x = abs(c-b); 19 | ll y = abs(c-1); 20 | 21 | ll sec_ele = x + y; 22 | 23 | 24 | if(f_ele < sec_ele) 25 | cout << "1" << '\n'; 26 | else if(sec_ele < f_ele) 27 | cout << "2" << '\n'; 28 | else 29 | cout << "3" << '\n'; 30 | } 31 | 32 | int main(void) 33 | { 34 | efficient; 35 | 36 | int t=1; 37 | cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /CodeForces/1746 A. Maxmina.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n, k, x, cnt=0; 16 | cin >> n >> k; 17 | vi vec(n); 18 | 19 | for (int i=0; i> x; 22 | vec.push_back(x); 23 | if(x==1) 24 | cnt=1; 25 | } 26 | if(cnt==1) 27 | cout << "YES" << endl; 28 | else 29 | cout << "NO" << endl; 30 | 31 | } 32 | 33 | int main(void) 34 | { 35 | //efficient; 36 | 37 | int t=1; 38 | cin>>t; 39 | while(t--) 40 | { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /CodeForces/1759 A. Yes-Yes.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define show(x) cout << #x << " : " << x << endl 11 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 12 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 13 | 14 | void solve() 15 | { 16 | string str, s; 17 | cin >> str; 18 | 19 | s = "YesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYes"; 20 | 21 | 22 | if (s.find(str) != string::npos) 23 | { 24 | cout << "Yes" << endl; 25 | return; 26 | } 27 | else 28 | cout << "No" << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CodeForces/271 A. Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | ll check_unique(ll num) 14 | { 15 | string s = to_string(num); 16 | 17 | set uniDigits(s.begin(), s.end()); 18 | 19 | if (s.size() == uniDigits.size()) 20 | { 21 | cout << num << '\n'; 22 | return 0; 23 | } 24 | 25 | } 26 | 27 | int main(void) 28 | { 29 | efficient; 30 | 31 | ll year, distinct_year; 32 | cin >> year; 33 | 34 | while(true) 35 | { 36 | year++; 37 | ll res = check_unique(year); 38 | if (res == 0) 39 | return 0; 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 18-Vowel Consonant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | char s[10001]; 7 | scanf(" %[^\n]", s); 8 | 9 | for(int i=0; s[i]!='\0'; i++) 10 | { 11 | if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || 12 | s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') 13 | cout << s[i]; 14 | } 15 | cout << '\n'; 16 | for(int i=0; s[i]!='\0'; i++) 17 | { 18 | if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && 19 | s[i] != 'A' && s[i] != 'E' && s[i] != 'I' && s[i] != 'O' && s[i] != 'U' && s[i] != ' ') 20 | cout << s[i]; 21 | } 22 | cout << '\n'; 23 | } 24 | 25 | int main(void) 26 | { 27 | int t; 28 | cin >> t; 29 | while (t--) 30 | { 31 | solve(); 32 | } 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /LeetCode/120. Triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | vector> dp; 3 | public: 4 | int solve (int row, int col, vector>& triangle) { 5 | if (row == triangle.size() - 1) return triangle[row][col]; 6 | if (dp[row][col] != INT32_MAX) return dp[row][col]; 7 | 8 | int ans = triangle[row][col]; 9 | 10 | int left = solve(row + 1, col, triangle); 11 | int right = solve(row + 1, col + 1, triangle); 12 | 13 | ans += min(left, right); 14 | 15 | return dp[row][col] = ans; 16 | } 17 | 18 | int minimumTotal(vector>& triangle) { 19 | int n = triangle.size(); 20 | 21 | // Assing INT32_MAX. Because -10^4 <= triangle[i][j] <= 10^4 22 | dp.assign(n + 5, vector(n + 5, INT32_MAX)); 23 | 24 | int ans = solve(0, 0, triangle); 25 | // Or, 26 | // ans = dp[0][0]; 27 | return ans; 28 | } 29 | }; -------------------------------------------------------------------------------- /LeetCode/2874. Maximum Value of an Ordered Triplet II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long maximumTripletValue(vector& nums) { 4 | int n = (int)nums.size(); 5 | vector pref_max(n, 0), suff_max(n, 0); 6 | pref_max[0] = nums[0], suff_max[n - 1] = nums[n - 1]; 7 | 8 | for (int i = 1; i < n; i++) 9 | pref_max[i] = max(pref_max[i - 1], nums[i]); 10 | for (int i = n - 2; i >= 0; i--) 11 | suff_max[i] = max(suff_max[i + 1], nums[i]); 12 | 13 | long long ans = INT64_MIN; 14 | for (int i = 1; i < n - 1; i++) { 15 | long long val = ((long long)pref_max[i - 1] - (long long)nums[i]) * 16 | (long long)suff_max[i + 1]; 17 | ans = max(ans, val); 18 | } 19 | 20 | return (ans < 0 ? 0 : ans); 21 | } 22 | // Every problem has its weakness. 23 | // This problem's weakness is...the existence of me! 24 | }; -------------------------------------------------------------------------------- /CodeForces/1749 A. Cowardly Rooks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n, m, x, y; 16 | cin >> n >> m; 17 | 18 | pair p[m+1]; 19 | 20 | for (int i=1; i<=m; i++) 21 | { 22 | cin >> x >> y; 23 | p[i].first = x; 24 | p[i].second = y; 25 | } 26 | 27 | if (n == m) 28 | cout << "NO" << endl; 29 | else 30 | cout << "YES" << endl; 31 | } 32 | 33 | int main(void) 34 | { 35 | efficient; 36 | 37 | int t=1; 38 | cin>>t; 39 | while(t--) 40 | { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1070 - Permutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n; 16 | cin >> n; 17 | 18 | if(n==1) 19 | cout << '1' << endl; 20 | else if (n>=4) 21 | { 22 | for (int i=2; i<=n; i+=2) 23 | cout << i << ' '; 24 | for (int i=1; i<=n; i+=2) 25 | cout << i << ' '; 26 | } 27 | else 28 | cout << "NO SOLUTION" << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | //cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/5. Permutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n; 16 | cin >> n; 17 | 18 | if(n==1) 19 | cout << '1' << endl; 20 | else if (n>=4) 21 | { 22 | for (int i=2; i<=n; i+=2) 23 | cout << i << ' '; 24 | for (int i=1; i<=n; i+=2) 25 | cout << i << ' '; 26 | } 27 | else 28 | cout << "NO SOLUTION" << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | //cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Square root of a number.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | 7 | // } Driver Code Ends 8 | // Function to find square root 9 | // x: element to find square root 10 | class Solution{ 11 | public: 12 | long long int floorSqrt(long long int x) 13 | { 14 | long long int l = 0, r = x, Sqrt; 15 | 16 | while (l <= r) { 17 | long long mid = l + (r - l) / 2; 18 | 19 | if ((mid * mid) <= x) { 20 | Sqrt = mid; 21 | l = mid + 1; 22 | } 23 | else r = mid - 1; 24 | } 25 | 26 | return Sqrt; 27 | } 28 | }; 29 | 30 | //{ Driver Code Starts. 31 | 32 | int main() 33 | { 34 | int t; 35 | cin>>t; 36 | while(t--) 37 | { 38 | long long n; 39 | cin>>n; 40 | Solution obj; 41 | cout << obj.floorSqrt(n) << endl; 42 | } 43 | return 0; 44 | } 45 | 46 | // } Driver Code Ends -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 35-Out of a Circle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int x1, x2, y1, y2; 16 | float r; 17 | cin >> x1 >> y1 >> r >> x2 >> y2; 18 | 19 | int x = abs(x2-x1); 20 | int y = abs(y2-y1); 21 | float distence = sqrt(x*x + y*y); 22 | 23 | if(distence > r) 24 | cout << "The point is not inside the circle" << endl; 25 | else 26 | cout << "The point is inside the circle" << endl; 27 | } 28 | 29 | int main(void) 30 | { 31 | //efficient; 32 | 33 | int t=1; 34 | cin>>t; 35 | while(t--) 36 | { 37 | solve(); 38 | } 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1069 - Repetitions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | string dna; 18 | cin >> dna; 19 | 20 | int max_rep = 0, rep = 0, len=dna.size(); 21 | char ch = dna[0]; 22 | 23 | for (int i=0; imax_rep) 32 | max_rep=rep; 33 | ch = dna[i]; 34 | rep = 1; 35 | } 36 | } 37 | if(rep>max_rep) 38 | max_rep=rep; 39 | 40 | cout << max_rep << '\n'; 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /AtCoder/ABC 280 C - Extra Charactor.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | string s, t; 19 | cin >> s >> t; 20 | 21 | for (int i=0; i>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /AtCoder/ABC 288 A - Many A+B Problems.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*-----------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | ll a, b; 23 | cin >> a >> b; 24 | cout << a+b << endl; 25 | } 26 | 27 | int main(void) 28 | { 29 | efficient; 30 | 31 | int t=1; 32 | cin>>t; 33 | while(t--) 34 | { 35 | solve(); 36 | } 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/3. Repetitions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | string dna; 18 | cin >> dna; 19 | 20 | int max_rep = 0, rep = 0, len=dna.size(); 21 | char ch = dna[0]; 22 | 23 | for (int i=0; imax_rep) 32 | max_rep=rep; 33 | ch = dna[i]; 34 | rep = 1; 35 | } 36 | } 37 | if(rep>max_rep) 38 | max_rep=rep; 39 | 40 | cout << max_rep << '\n'; 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 37-Number Disaster.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int num, rev = 0; 19 | cin >> num; 20 | 21 | while(num!=0) 22 | { 23 | rev = rev * 10; 24 | rev = rev + num%10; 25 | num = num/10; 26 | } 27 | 28 | cout << rev << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CodeForces/1764 B. Doremy's Perfect Math Class.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n, temp = 0; 19 | cin >> n; 20 | int a[n]; 21 | 22 | for (int i=0; i> a[i]; 25 | temp = __gcd(temp, a[i]); 26 | } 27 | 28 | cout << a[n-1]/temp << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CodeForces/1743 B. Permutation Value.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define show(x) cout << #x << " : " << x << endl 11 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 12 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 13 | 14 | void solve() 15 | { 16 | int n; 17 | cin >> n; 18 | 19 | for (int i=1; i<=n; i+=2) 20 | cout << i << ' '; 21 | 22 | if (n%2!=0) 23 | { 24 | for (int i=n-1; i>=1; i-=2) 25 | cout << i << ' '; 26 | } 27 | else 28 | { 29 | for (int i=n; i>=1; i-=2) 30 | cout << i << ' '; 31 | } 32 | 33 | cout << endl; 34 | } 35 | 36 | int main(void) 37 | { 38 | efficient; 39 | 40 | int t=1; 41 | cin>>t; 42 | while(t--) 43 | { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /LeetCode/518. Coin Change II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[305][5005]; // [number of coins][maximun number input] 4 | 5 | int solve(int idx, int total, vector &coin) { 6 | if (idx == (int) coin.size() or total == 0) { 7 | if (total == 0) 8 | return 1; 9 | else 10 | return 0; 11 | // return (total == 0); // In short 12 | } 13 | if (dp[idx][total] != -1) 14 | return dp[idx][total]; 15 | 16 | int ans = 0; 17 | for (int i = 0; i <= total; i++) { 18 | if (total - (i * coin[idx]) >= 0) 19 | ans += solve(idx + 1, (total - (i * coin[idx])), coin); 20 | else 21 | break; 22 | } 23 | 24 | return dp[idx][total] = ans; 25 | } 26 | 27 | int change(int amount, vector& coins) { 28 | memset(dp, -1, sizeof(dp)); 29 | 30 | int ans = solve(0, amount, coins); 31 | return ans; 32 | } 33 | }; -------------------------------------------------------------------------------- /CodeForces/1742 B. Increasing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n, flag = 1; 16 | cin >> n; 17 | 18 | int arr[n]; 19 | for (int i=0; i> arr[i]; 21 | sort(arr, arr+n); 22 | 23 | for (int i=n-1; i>0; i--) 24 | { 25 | if(arr[i] == arr[i-1]) 26 | flag = 0; 27 | } 28 | 29 | if (flag == 1) 30 | cout << "YES" << '\n'; 31 | else if (flag == 0) 32 | cout << "NO" << '\n'; 33 | 34 | } 35 | 36 | int main(void) 37 | { 38 | efficient; 39 | 40 | int t=1; 41 | cin>>t; 42 | while(t--) 43 | { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /CodeForces/1754 B. Kevin and Permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n; 16 | cin >> n; 17 | 18 | int arr[n]; 19 | int x = (n/2)+1; 20 | 21 | for (int i=0; i>t; 45 | while(t--) 46 | { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /AtCoder/ABC 280 B - Inverse Prefix Sum.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; 19 | cin >> n; 20 | ll arr[n+1]; 21 | arr[0] = 0; 22 | 23 | for (int i=1; i<=n; i++) 24 | cin >> arr[i]; 25 | 26 | for (int i = 1; i<=n; i++) 27 | { 28 | cout << arr[i]-arr[i-1] << " "; 29 | } 30 | } 31 | 32 | int main(void) 33 | { 34 | //efficient; 35 | 36 | int t=1; 37 | //cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /CodeForces/1722 A. Spell Check.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | int t; 18 | cin >> t; 19 | 20 | while(t--) 21 | { 22 | int n; 23 | cin >> n; 24 | 25 | string name, base; 26 | cin >> name; 27 | base = "Timur"; 28 | 29 | sort(base.begin(), base.end()); 30 | 31 | if (n>5 && n<5) 32 | cout << "NO" << '\n'; 33 | else 34 | { 35 | sort(name.begin(), name.end()); 36 | if(name == base) 37 | cout << "YES" << '\n'; 38 | else 39 | cout << "NO" << '\n'; 40 | } 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /CodeForces/1754 A. Technical Support.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n, count = 0; 16 | cin >> n; 17 | 18 | string dialog; 19 | cin >> dialog; 20 | 21 | for (int i=0; i>t; 44 | while(t--) 45 | { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /CodeForces/59 A. Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | 13 | int main(void) 14 | { 15 | efficient; 16 | 17 | string line; 18 | int upper = 0, lower = 0; 19 | cin >> line; 20 | 21 | for (int i=0; i upper) || (lower == upper)) 29 | { 30 | transform(line.begin(), line.end(), line.begin(), ::tolower); 31 | cout << line << '\n'; 32 | } 33 | else if(lower < upper) 34 | { 35 | transform(line.begin(), line.end(), line.begin(), ::toupper); 36 | cout << line << '\n'; 37 | } 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 40-Sum of Series 1.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int x, k; 19 | cin >> x >> k; 20 | 21 | int sum = 1, power = 1; 22 | for (int i=1; i<=k; i++) 23 | { 24 | power = power * x; 25 | sum = sum + power; 26 | } 27 | 28 | cout << "Result = " << sum << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CodeForces/1592 A. Gamer Hemose.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | 6 | void solve() 7 | { 8 | ll num_wep, health; 9 | cin >> num_wep >> health; 10 | 11 | ll power[num_wep]; 12 | 13 | for (ll i=0; i> power[i]; 16 | } 17 | 18 | sort(power, power+num_wep, greater()); 19 | 20 | ll sum_pow = power[0] + power[1]; 21 | 22 | if(power[0] >= health) 23 | cout << '1' << '\n'; 24 | else if(sum_pow >= health) 25 | cout << '2' << '\n'; 26 | else 27 | { 28 | if(health%sum_pow == 0) 29 | cout << (health/sum_pow)*2 << '\n'; 30 | else if(health%sum_pow <= power[0]) 31 | cout << (health/sum_pow)*2+1 << '\n'; 32 | else 33 | cout << (health/sum_pow)*2+2 << '\n'; 34 | } 35 | 36 | } 37 | 38 | int main(void) 39 | { 40 | int t; 41 | cin >> t; 42 | 43 | while (t--) 44 | { 45 | solve(); 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /AtCoder/ARC 087 C - Good Sequence.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | #define endl '\n' 6 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 7 | 8 | /*---------------------------------------------------------------------------------------------------------------*/ 9 | 10 | void solve() 11 | { 12 | int n; cin >> n; 13 | 14 | map freq; 15 | int x; 16 | for (int i = 0; i < n; i++) 17 | { 18 | cin >> x; 19 | freq[x]++; 20 | } 21 | 22 | int ans = 0; 23 | for (auto &&i : freq) 24 | { 25 | if (i.second >= i.first) ans += (i.second - i.first); 26 | else ans += i.second; 27 | } 28 | 29 | cout << ans << endl; 30 | } 31 | 32 | int main(void) 33 | { 34 | efficient(); 35 | 36 | int t = 1; 37 | // cin >> t; 38 | for (int tc = 1; tc <= t; tc++) 39 | { 40 | // cout << "Case " << tc << ": "; 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1617 - Bit Strings.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | 19 | void solve() 20 | { 21 | ll n; 22 | cin >> n; 23 | 24 | ll ans = 1; 25 | 26 | for (int i=1; i<=n; i++) 27 | { 28 | ans = ans * 2; 29 | ans = ans % MOD; 30 | } 31 | 32 | cout << ans << endl; 33 | } 34 | 35 | int main(void) 36 | { 37 | //efficient; 38 | 39 | int t=1; 40 | //cin>>t; 41 | while(t--) 42 | { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /CodeForces/1747 B. BAN BAN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | int n; 16 | cin >> n; 17 | if(n==1) 18 | { 19 | cout << "1" << endl; 20 | cout << "1 2" << endl; 21 | return; 22 | } 23 | int op; 24 | if(n%2==0) 25 | op=n/2; 26 | else 27 | op=(n/2)+1; 28 | cout << op << endl; 29 | int x = 2, y = n*3; 30 | 31 | for (int i=1; i<=op; i++) 32 | { 33 | cout << x << ' ' << y << endl; 34 | x+=3; y-=3; 35 | } 36 | 37 | } 38 | 39 | int main(void) 40 | { 41 | efficient; 42 | 43 | int t=1; 44 | cin>>t; 45 | while(t--) 46 | { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /CodeForces/1721 B. Deadly Laser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | void solve() 13 | { 14 | int row, col, Sx, Sy, d, start_to_end, Gx1, Gy1, Gx2, Gy2; 15 | cin >> row >> col >> Sx >> Sy >> d; 16 | 17 | start_to_end = abs(1-row) + abs(1-col); 18 | 19 | 20 | Gx1 = abs(Sx-Sx) + abs(Sy-1); 21 | Gy1 = abs(Sx-1) + abs(Sy-Sy); 22 | Gx2 = col-Gx1-1; 23 | Gy2 = row-Gy1-1; 24 | 25 | if ((Gx1 > d && Gy2 > d) || (Gy1 > d && Gx2 > d)) 26 | cout << start_to_end << endl; 27 | 28 | else 29 | cout << "-1" << endl; 30 | 31 | } 32 | 33 | int main(void) 34 | { 35 | efficient; 36 | 37 | int t; 38 | cin>>t; 39 | while (t--) 40 | { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 39-Palindrome.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | string s1, s2; 19 | cin >> s1; 20 | 21 | s2 = s1; 22 | 23 | reverse(s2.begin(), s2.end()); 24 | 25 | if (s1 == s2) 26 | cout << "Yes! It is palindrome!" << endl; 27 | else 28 | cout << "Sorry! It is not palindrome!" << endl; 29 | 30 | } 31 | 32 | int main(void) 33 | { 34 | efficient; 35 | 36 | int t=1; 37 | cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/9. Bit Strings.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | 19 | void solve() 20 | { 21 | ll n; 22 | cin >> n; 23 | 24 | ll ans = 1; 25 | 26 | for (int i=1; i<=n; i++) 27 | { 28 | ans = ans * 2; 29 | ans = ans % MOD; 30 | } 31 | 32 | cout << ans << endl; 33 | } 34 | 35 | int main(void) 36 | { 37 | //efficient; 38 | 39 | int t=1; 40 | //cin>>t; 41 | while(t--) 42 | { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /CodeForces/1732 B. Ugu.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; cin >> n; 19 | string s; cin >> s; 20 | 21 | int ans = 0; 22 | 23 | for (int i=0; i 0 and s.back() == '0') 30 | ans--; 31 | 32 | cout << ans << endl; 33 | } 34 | 35 | int main(void) 36 | { 37 | efficient; 38 | 39 | int t=1; 40 | cin>>t; 41 | while(t--) 42 | { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /LeetCode/3027. Find the Number of Ways to Place People II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfPairs(vector>& points) { 4 | int n = (int) points.size(); 5 | int ans = 0; 6 | 7 | auto cmp = [&](vector& a, vector& b) { 8 | if (a[0] != b[0]) 9 | return a[0] < b[0]; 10 | else 11 | return a[1] > b[1]; 12 | }; 13 | 14 | sort(points.begin(), points.end(), cmp); 15 | 16 | for (int i = 0; i < n; i++) { 17 | int alice_x = points[i][0]; 18 | int alice_y = points[i][1]; 19 | 20 | int lower_y = INT32_MIN; 21 | for (int j = i + 1; j < n; j++) { 22 | int bob_x = points[j][0]; 23 | int bob_y = points[j][1]; 24 | 25 | if (bob_y > alice_y) continue; 26 | if (bob_y > lower_y) { 27 | ans++; 28 | lower_y = bob_y; 29 | } 30 | } 31 | } 32 | 33 | return ans; 34 | } 35 | }; -------------------------------------------------------------------------------- /AtCoder/ABC 281 A - Count Down.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*----------------------------------------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n; 23 | cin >> n; 24 | 25 | for (int i=n; i>=0; i--) 26 | cout << i << endl; 27 | } 28 | 29 | int main(void) 30 | { 31 | //efficient; 32 | 33 | int t=1; 34 | //cin>>t; 35 | while(t--) 36 | { 37 | solve(); 38 | } 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /CodeForces/1720 A. Burenka Plays with Fractions.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll a, b, c, d; 19 | cin >> a >> b >> c >> d; 20 | 21 | ll x = a*d; 22 | ll y = c*b; 23 | 24 | if (x == y) 25 | cout << 0 << endl; 26 | else if ((x!=0 && y%x==0) || (y!=0 && x%y==0)) 27 | cout << 1 << endl; 28 | else 29 | cout << 2 << endl; 30 | } 31 | 32 | int main(void) 33 | { 34 | efficient; 35 | 36 | int t=1; 37 | cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /CodeForces/1722 B. Colourblindness.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define show(x) cout << #x << " : " << x << endl 9 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 10 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 11 | 12 | void solve() 13 | { 14 | int n; 15 | cin >> n; 16 | 17 | string row1, row2; 18 | cin >> row1; 19 | cin >> row2; 20 | int c=1; 21 | for (int i=0; i> t; 41 | 42 | while(t--) 43 | { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /AtCoder/ABC 280 A - Pawn on a Grid.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int h, w, cnt=0; 19 | cin >> h >> w; 20 | 21 | string s; 22 | for (int i=1; i<=h; i++) 23 | { 24 | cin >> s; 25 | for (int i=0; i>t; 40 | while(t--) 41 | { 42 | solve(); 43 | } 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CodeForces/1758 B. XOR = Average.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; 19 | cin >> n; 20 | 21 | if (n%2 == 1) 22 | { 23 | for (int i=1; i<=n; i++) 24 | cout << "1" << " "; 25 | cout << endl; 26 | } 27 | else 28 | { 29 | for (int i=1; i>t; 41 | while(t--) 42 | { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /CodeForces/469 A. I Wanna Be the Guy.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef unsigned long long ull; 7 | 8 | #define endl '\n' 9 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 10 | #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); 11 | 12 | /*---------------------------------------------------------------------------------------------------------------*/ 13 | 14 | int main(void) 15 | { 16 | efficient(); 17 | 18 | set s; 19 | int n; cin >> n; 20 | 21 | int p; cin >> p; 22 | for (int i = 0; i < p; i++) 23 | { 24 | int x; cin >> x; 25 | s.insert(x); 26 | } 27 | 28 | cin >> p; 29 | for (int i = 0; i < p; i++) 30 | { 31 | int x; cin >> x; 32 | s.insert(x); 33 | } 34 | 35 | if (s.size() == n) cout << "I become the guy." << endl; 36 | else cout << "Oh, my keyboard!" << endl; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /CodeForces/GYM 104077 J. Strange Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define debug(x) cout << #x << " = "; cout << x << '\n'; 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | ll Maximum_Subarray_sum(vector &Name){ 7 | ll n = Name.size(); 8 | ll Ans = Name[0], Sum = Name[0]; 9 | for(ll ii = 1; ii < n; ii++){ 10 | Sum = max(Sum + Name[ii], Name[ii]); 11 | Ans = max(Ans, Sum); 12 | } 13 | return Ans; 14 | } 15 | 16 | void idea() { 17 | ll n; 18 | cin >> n; 19 | vector v(n); 20 | for(auto &ii : v) { 21 | cin >> ii; 22 | } 23 | 24 | sort(v.begin(), v.end()); 25 | 26 | ll ans = 0; 27 | if(v[n - 1] > 0) { 28 | ans += v[n - 1]; 29 | } 30 | if(v[n - 2] > 0) { 31 | ans += v[n - 2]; 32 | } 33 | cout << ans << '\n'; 34 | } 35 | 36 | int main() { 37 | ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 38 | int T = 1; 39 | // cin >> T; 40 | for(int C = 1; C <= T; C++) { 41 | // cout << "Case " << C << ": " << '\n'; 42 | idea(); 43 | } 44 | return 0; 45 | } -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Reverse First K elements of Queue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | queue modifyQueue(queue q, int k); 4 | int main() { 5 | int t; 6 | cin >> t; 7 | while (t-- > 0) { 8 | int n, k; 9 | cin >> n >> k; 10 | queue q; 11 | while (n-- > 0) { 12 | int a; 13 | cin >> a; 14 | q.push(a); 15 | } 16 | queue ans = modifyQueue(q, k); 17 | while (!ans.empty()) { 18 | int a = ans.front(); 19 | ans.pop(); 20 | cout << a << " "; 21 | } 22 | cout << endl; 23 | } 24 | } 25 | 26 | queue modifyQueue(queue q, int k) { 27 | stack st; 28 | queue ans; 29 | 30 | while(k--) { 31 | st.push(q.front()); 32 | q.pop(); 33 | } 34 | 35 | while(!st.empty()) { 36 | ans.push(st.top()); 37 | st.pop(); 38 | } 39 | 40 | while(!q.empty()) { 41 | ans.push(q.front()); 42 | q.pop(); 43 | } 44 | 45 | return ans; 46 | } -------------------------------------------------------------------------------- /LeetCode/1004. Max Consecutive Ones III.cpp: -------------------------------------------------------------------------------- 1 | // Solution 1: Using Binary Search 2 | // ------------------------------------- 3 | class Solution { 4 | public: 5 | int longestOnes(vector& nums, int k) { 6 | nums.insert(nums.begin() + 0, 0); 7 | int n = nums.size(); 8 | 9 | // Prefix sum 10 | for (int i = 1; i < n; i++) 11 | nums[i] = nums[i - 1] + nums[i]; 12 | 13 | int ans = 0; 14 | 15 | for (int i = 1; i < n; i++) { 16 | int l = i, r = n - 1; 17 | while (l <= r) { 18 | int mid = l + (r - l) / 2; 19 | 20 | int val = nums[mid] - nums[i - 1]; 21 | int len = mid - i + 1; 22 | int flip_need = len - val; 23 | 24 | if (flip_need <= k) { 25 | ans = max(ans, len); 26 | l = mid + 1; 27 | } 28 | else r = mid - 1; 29 | } 30 | } 31 | 32 | return ans; 33 | } 34 | }; 35 | 36 | // Solution 2: Sliding Window 37 | // --------------------------------------------- -------------------------------------------------------------------------------- /LeetCode/983. Minimum Cost For Tickets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[370]; 4 | 5 | int findCost(int idx, vector& days, vector& costs, 6 | vector& day_pass) { 7 | if (idx == (int)days.size()) 8 | return 0; 9 | if (dp[idx] != -1) 10 | return dp[idx]; 11 | 12 | int ans = INT32_MAX; 13 | for (int i = 0; i < 3; i++) { 14 | int next = days[idx] + day_pass[i] - 1; 15 | 16 | int next_idx = idx; 17 | while (next_idx < days.size() and days[next_idx] <= next) 18 | next_idx++; 19 | 20 | int curr_cost = 21 | costs[i] + findCost(next_idx, days, costs, day_pass); 22 | 23 | ans = min(ans, curr_cost); 24 | } 25 | 26 | return dp[idx] = ans; 27 | } 28 | 29 | int mincostTickets(vector& days, vector& costs) { 30 | memset(dp, -1, sizeof(dp)); 31 | vector day_pass = {1, 7, 30}; 32 | 33 | int ans = findCost(0, days, costs, day_pass); 34 | return ans; 35 | } 36 | }; -------------------------------------------------------------------------------- /CodeForces/1650 B. DIV + MOD.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll l, r, a; 19 | cin >> l >> r >> a; 20 | 21 | ll ans = (r/a) + (r%a); 22 | 23 | if (a==1) 24 | { 25 | cout << r << endl; 26 | return; 27 | } 28 | 29 | if (r-(r%a)-1 >= l) 30 | { 31 | r = r-(r%a)-1; 32 | } 33 | 34 | ans = max(ans, (r/a) + (r%a)); 35 | cout << ans << endl; 36 | } 37 | 38 | int main(void) 39 | { 40 | efficient; 41 | 42 | int t=1; 43 | cin>>t; 44 | while(t--) 45 | { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 16-Word Disaster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print_reverse(char str[]) 5 | { 6 | for (int i=strlen(str) - 1; i>=0; i--) 7 | { 8 | cout << str[i]; 9 | } 10 | } 11 | 12 | void solve() 13 | { 14 | char s[1002], word[1002]; // Using "string" data type will be show error because scanf(" %[^\n]", s); 15 | scanf(" %[^\n]", s); 16 | //cout << s << "\n"; 17 | 18 | int j, k; 19 | for (j=0, k=0; j0) 27 | { 28 | word[k] = '\0'; 29 | print_reverse(word); 30 | cout << ' '; 31 | k = 0; 32 | } 33 | } 34 | if (k>0) 35 | { 36 | word[k] = '\0'; 37 | print_reverse(word); 38 | cout << '\n'; 39 | } 40 | } 41 | 42 | int main(void) 43 | { 44 | int t; 45 | cin >> t; 46 | while (t--) 47 | { 48 | solve(); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /GeeksForGeeks Practice/Special Stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | void push(stack& s,int a); 5 | bool isFull(stack& s,int n); 6 | bool isEmpty(stack& s); 7 | int pop(stack& s); 8 | int getMin(stack& s); 9 | //This is the STL stack (http://quiz.geeksforgeeks.org/stack-container-adaptors-the-c-standard-template-library-stl/). 10 | stack s; 11 | int main(){ 12 | int t; 13 | cin>>t; 14 | while(t--){ 15 | int n,a; 16 | cin>>n; 17 | while(!isEmpty(s)){ 18 | pop(s); 19 | } 20 | while(!isFull(s,n)){ 21 | cin>>a; 22 | push(s,a); 23 | } 24 | cout<& s, int a){ 31 | s.push(a); 32 | } 33 | 34 | bool isFull(stack& s,int n){ 35 | return ( s.size() == n ); 36 | } 37 | 38 | bool isEmpty(stack& s){ 39 | return ( s.empty() ); 40 | } 41 | 42 | int pop(stack& s){ 43 | s.pop(); 44 | } 45 | 46 | int getMin(stack& s){ 47 | int mn = s.top(); 48 | while ( !s.empty() ) { 49 | mn = min( mn, s.top() ); 50 | s.pop(); 51 | } 52 | return mn; 53 | } -------------------------------------------------------------------------------- /AtCoder/ABC 292 A - CAPS LOCK.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef vector vll; 8 | typedef pair pi; 9 | 10 | #define endl '\n' 11 | #define yes cout << "YES" << endl 12 | #define no cout << "NO" << endl 13 | #define show(x) cout << #x << " : " << x << endl 14 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 15 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 16 | 17 | const ll MOD = 1e9 + 7; // 1000000007; 18 | 19 | /*---------------------------------------------------------------------------------------------------------------*/ 20 | 21 | void solve() 22 | { 23 | string s1; 24 | cin >> s1; 25 | 26 | transform(s1.begin(), s1.end(), s1.begin(), ::toupper); 27 | 28 | cout << s1 << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | //efficient; 34 | 35 | int t=1; 36 | //cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /AtCoder/ABC 118 A - A - B +- A.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*----------------------------------------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int a, b; 23 | cin >> a >> b; 24 | 25 | if (b%a == 0) 26 | cout << a+b << endl; 27 | else 28 | cout << b-a << endl; 29 | } 30 | 31 | int main(void) 32 | { 33 | efficient; 34 | 35 | int t=1; 36 | //cin>>t; 37 | while(t--) 38 | { 39 | solve(); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /CodeForces/1617 B. GCD Problem.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; 19 | cin >> n; 20 | if (n%2 == 0) 21 | cout << "2 " << (n-1)-2 << " 1" << endl; 22 | else 23 | { 24 | int cur = (n-1)/2; 25 | if (cur%2 == 0) 26 | cout << cur-1 << " " << cur+1 << " " << 1 << endl; 27 | else 28 | cout << cur-2 << " " << cur+2 << " " << 1 << endl; 29 | } 30 | } 31 | 32 | int main(void) 33 | { 34 | efficient; 35 | 36 | int t=1; 37 | cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /LeetCode/3494. Find the Minimum Amount of Time to Brew Potions.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minTime(vector& skill, vector& mana) { 4 | int n = (int) skill.size(); 5 | int m = (int) mana.size(); 6 | 7 | vector time(n, 0); 8 | for (int i = 0; i < m; i++) { 9 | long long val = mana[i]; 10 | for (int j = 0; j < n; j++) { 11 | // For first wizard 12 | if (j == 0) time[j] = time[j] + (skill[j] * val); 13 | 14 | // For 2nd to last wizard add time with previous one 15 | if (j != 0) time[j] = time[j - 1] + (skill[j] * val); 16 | 17 | // Check when the next wizard will finish and adjust it will current wizard. 18 | if (j + 1 < n) time[j] = max(time[j], time[j + 1]); 19 | } 20 | 21 | // Now final adjustment according to the last time. 22 | for (int j = n - 2; j >= 0; j--) { 23 | time[j] = time[j + 1] - (skill[j + 1] * val); 24 | } 25 | } 26 | 27 | return time[n - 1]; 28 | } 29 | }; -------------------------------------------------------------------------------- /LeetCode/904. Fruit Into Baskets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int totalFruit(vector& fruits) { 4 | int n = (int) fruits.size(); 5 | 6 | if (n == 1) return 1; 7 | 8 | int l = 0, r = n - 1; 9 | for (int i = 0; i < n; i++) { 10 | if (fruits[i] != fruits[0]) { 11 | r = i; 12 | break; 13 | } 14 | } 15 | int ans = r - l + 1; 16 | 17 | int first = fruits[l], second = fruits[r]; 18 | 19 | for (int i = r + 1; i < n; i++) { 20 | if (fruits[i] == first or fruits[i] == second) { 21 | r = i; 22 | ans = max(ans, (r - l + 1)); 23 | } 24 | else { 25 | first = fruits[i - 1], second = fruits[i]; 26 | 27 | l = i - 1, r = i; 28 | for (int j = l; j >= 0; j--) { 29 | if (fruits[j] == fruits[l]) l = j; 30 | else break; 31 | } 32 | 33 | ans = max(ans, (r - l + 1)); 34 | } 35 | } 36 | 37 | return ans; 38 | } 39 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Mehedi-Hasan-Rabbi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CodeForces/1735 B. Tea with Tangerines.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll n; 19 | cin >> n; 20 | 21 | vector v(n); 22 | 23 | for (ll i=0; i> v[i]; 25 | 26 | 27 | ll x = v[0]; 28 | ll mx = 2*x-1; 29 | ll ans = 0; 30 | 31 | for (ll i=1; i>t; 47 | while(t--) 48 | { 49 | solve(); 50 | } 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 43-Calculation.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*---------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int p, q, r, temp = 1; 23 | cin >> p >> q >> r; 24 | 25 | for (int i = 1; i <= q; i++) 26 | { 27 | temp = (temp * p) % r; 28 | } 29 | cout << "Result = " << temp << endl; 30 | } 31 | 32 | int main(void) 33 | { 34 | //efficient; 35 | 36 | int t=1; 37 | cin>>t; 38 | while(t--) 39 | { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /LeetCode/808. Soup Servings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> op = { {4, 0}, {3, 1}, {2, 2}, {1, 3} }; 4 | vector> dp; 5 | 6 | double prob (int a, int b) { 7 | if (a == 0 and b > 0) return 1.0; // A is empty but B is not 8 | if (a == 0 and b == 0) return 0.5; // A and B both are empty 9 | if (a > 0 and b == 0) return 0.0; // A si not empty but B is empty 10 | if (dp[a][b] > -0.5) return dp[a][b]; // Memorization 11 | 12 | double ans = 0.0; 13 | for (int i = 0; i < 4; i++) { 14 | int aa = max(0, (a - op[i][0])); 15 | int bb = max(0, (b - op[i][1])); 16 | 17 | ans += 0.25 * prob( aa, bb ); // since each operation has 1 / 4 = 0.25 probability 18 | } 19 | 20 | return dp[a][b] = ans; 21 | } 22 | 23 | double soupServings(int n) { 24 | int serve = (n / 25) + (n % 25 != 0); // Ceil Value 25 | 26 | if (serve >= 200) return 1; 27 | 28 | dp.assign(n + 5, vector(n + 5, -1.0)); 29 | 30 | double ans = (prob(serve, serve)); 31 | return ans; 32 | } 33 | }; -------------------------------------------------------------------------------- /CodeForces/1714 A. Everyone Loves to Sleep.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n, H, M, time; 19 | cin >> n >> H >> M; 20 | 21 | time = 60*H + M; 22 | int ans = 24*60; 23 | 24 | for (int i=0; i> H >> M; 27 | int t = 60*H + M - time; 28 | 29 | if (t<0) 30 | t = t + 24*60; 31 | 32 | ans = min(ans, t); 33 | } 34 | 35 | cout << (ans/60) << " " << (ans%60) << endl; 36 | 37 | } 38 | 39 | int main(void) 40 | { 41 | efficient; 42 | 43 | int t=1; 44 | cin>>t; 45 | while(t--) 46 | { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /CodeForces/1731 A. Joey Takes Money.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*-----------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n, x; 23 | cin >> n; 24 | 25 | ll sum = 1; 26 | for (int i=0; i> x; 29 | sum = sum * x; 30 | } 31 | 32 | sum = sum + (n-1); 33 | 34 | cout << sum*2022 << endl; 35 | } 36 | 37 | int main(void) 38 | { 39 | efficient; 40 | 41 | int t=1; 42 | cin>>t; 43 | while(t--) 44 | { 45 | solve(); 46 | } 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 38-Diamond Kingdom.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int l, n; 19 | cin >> l >> n; 20 | 21 | for (int i=1; i<=l; i++) 22 | { 23 | for (int j=1; j<=i; j++) 24 | cout << n << " "; 25 | cout << endl; 26 | } 27 | for (int i=l-1; i>=1; i--) 28 | { 29 | for (int j=1; j<=i; j++) 30 | cout << n << " "; 31 | cout << endl; 32 | } 33 | 34 | cout << endl; 35 | } 36 | 37 | int main(void) 38 | { 39 | efficient; 40 | 41 | int t=1; 42 | cin>>t; 43 | while(t--) 44 | { 45 | solve(); 46 | } 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 42-Sum of Series 3.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*---------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n; 23 | cin >> n; 24 | 25 | for (int i = n; i >= 0; i--) 26 | { 27 | if (i==0) cout << "1" << endl; 28 | else if (i==1) cout << "2 + "; 29 | else printf("2^%d + ", i); 30 | } 31 | 32 | } 33 | 34 | int main(void) 35 | { 36 | //efficient; 37 | 38 | int t=1; 39 | cin>>t; 40 | while(t--) 41 | { 42 | solve(); 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /CodeForces/1791 A. Codeforces Checking.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*-----------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | char ch; 23 | cin >> ch; 24 | 25 | string s = "codeforces"; 26 | 27 | for (int i=0; i>t; 45 | while(t--) 46 | { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 28-Random Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int acending(int *arr, int *n) 5 | { 6 | int sorted = 1; 7 | for (int i=1; i<*n; i++) 8 | { 9 | if(arr[i] < arr[i-1]) 10 | { 11 | sorted = 0; 12 | break; 13 | } 14 | } 15 | return sorted; 16 | } 17 | 18 | int descending(int *arr, int *n) 19 | { 20 | int sorted = 1; 21 | for (int i=1; i<*n; i++) 22 | { 23 | if(arr[i] > arr[i-1]) 24 | { 25 | sorted = 0; 26 | break; 27 | } 28 | } 29 | return sorted; 30 | } 31 | 32 | void solve() 33 | { 34 | int n; 35 | cin>>n; 36 | 37 | int arr[n]; 38 | 39 | for (int i=0; i> arr[i]; 41 | 42 | int asc = acending(arr, &n); 43 | int des = descending(arr, &n); 44 | 45 | if(asc==1) 46 | cout << "YES" << endl; 47 | else if(des==1) 48 | cout << "YES" << endl; 49 | else 50 | cout << "NO" << endl; 51 | } 52 | 53 | int main(void) 54 | { 55 | int t=1; 56 | cin>>t; 57 | while(t--) 58 | { 59 | solve(); 60 | } 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 46-Area of Triangle.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef vector vll; 8 | typedef pair pi; 9 | 10 | #define endl '\n' 11 | #define yes cout << "Yes" << endl 12 | #define no cout << "No" << endl 13 | #define show(x) cout << #x << " : " << x << endl 14 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 15 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 16 | 17 | const ll MOD = 1e9 + 7; // 1000000007; 18 | 19 | /*---------------------------------------------------------------------------------------------------------------*/ 20 | 21 | void solve() 22 | { 23 | double a, b, c; 24 | cin >> a >> b >> c; 25 | 26 | double s = (a+b+c)/2; 27 | 28 | // √[s(s-a)(s-b)(s-c)] 29 | double area = sqrt(s * (s-a) * (s-b) * (s-c)); 30 | printf("Area = %.3lf\n", area); 31 | } 32 | 33 | int main(void) 34 | { 35 | //efficient; 36 | 37 | int t=1; 38 | cin>>t; 39 | while(t--) 40 | { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /AtCoder/ABC 288 B - Qualification Contest.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*-----------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n, pos; 23 | cin >> n >> pos; 24 | 25 | string s[n]; 26 | for (int i = 0; i < n; i++) 27 | { 28 | cin >> s[i]; 29 | } 30 | sort(s, s+pos); 31 | for (int i = 0; i < pos; i++) 32 | { 33 | cout << s[i] << endl; 34 | } 35 | 36 | } 37 | 38 | int main(void) 39 | { 40 | efficient; 41 | 42 | int t=1; 43 | //cin>>t; 44 | while(t--) 45 | { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /CodeForces/1759 C. Thermostat.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll l, r, x; 19 | cin >> l >> r >> x; 20 | ll a, b; 21 | cin >> a >> b; 22 | 23 | if (a==b) cout << 0 << endl; 24 | else if (abs(a-b)>=x) cout << 1 << endl; 25 | else if (abs(a-r)>=x and abs(b-r)>=x ) cout << 2 << endl; 26 | else if (abs(a-l)>=x and abs(b-l)>=x ) cout << 2 << endl; 27 | else if (abs(a-r)>=x and abs(b-l)>=x ) cout << 3 << endl; 28 | else if (abs(a-l)>=x and abs(b-r)>=x ) cout << 3 << endl; 29 | else cout << -1 << endl; 30 | 31 | } 32 | 33 | int main(void) 34 | { 35 | efficient; 36 | 37 | int t=1; 38 | cin>>t; 39 | while(t--) 40 | { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /CodeForces/1675 B. Make It Increasing.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n, ans = 0; 19 | cin >> n; 20 | 21 | vector v(n); 22 | 23 | for (auto &i: v) 24 | cin >> i; 25 | 26 | for (int i=n-2; i>=0; --i) 27 | { 28 | while(v[i] !=0 and v[i]>=v[i+1]) 29 | { 30 | v[i] = v[i]/2; 31 | ans++; 32 | } 33 | 34 | if(v[i] == v[i+1]) 35 | { 36 | cout << -1 << endl; 37 | return; 38 | } 39 | } 40 | cout << ans << endl; 41 | } 42 | 43 | int main(void) 44 | { 45 | efficient; 46 | 47 | int t=1; 48 | cin>>t; 49 | while(t--) 50 | { 51 | solve(); 52 | } 53 | return 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /CodeForces/1766 A. Extremely Round.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*----------------------------------------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n, ans=0; 23 | cin >> n; 24 | 25 | string s = to_string(n); 26 | int sz = s.size(); 27 | 28 | char ch = s[0]; 29 | 30 | int digit = (int) ch - 48; 31 | 32 | ans = sz-1; 33 | ans = ans*9; 34 | ans = ans+digit; 35 | 36 | cout << ans << endl; 37 | } 38 | 39 | int main(void) 40 | { 41 | efficient; 42 | 43 | int t=1; 44 | cin>>t; 45 | while(t--) 46 | { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /LeetCode/682. Baseball Game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int calPoints(vector& operations) { 4 | stack st; 5 | 6 | for (auto u: operations) 7 | { 8 | if ( u.size() > 1 ) 9 | st.push( stoi(u) ); 10 | else { 11 | if (isdigit(u[0])) st.push(u[0] - '0'); 12 | else if (u[0] == '+') { 13 | if (st.size() >= 2) { 14 | int top1 = st.top(); 15 | st.pop(); 16 | int top2 = st.top(); 17 | st.pop(); 18 | 19 | st.push(top2); 20 | st.push(top1); 21 | st.push(top1 + top2); 22 | } 23 | } 24 | else if (u[0] == 'D') { 25 | if (!st.empty()) st.push( 2 * st.top() ); 26 | } 27 | else { 28 | if (!st.empty()) st.pop(); 29 | } 30 | } 31 | } 32 | 33 | long long ans = 0LL; 34 | while(!st.empty()) { 35 | ans += (long long) st.top(); 36 | st.pop(); 37 | } 38 | 39 | return ans; 40 | } 41 | }; -------------------------------------------------------------------------------- /AtCoder/ABC 291 A - camel Case.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef vector vll; 8 | typedef pair pi; 9 | 10 | #define endl '\n' 11 | #define yes cout << "Yes" << endl 12 | #define no cout << "No" << endl 13 | #define show(x) cout << #x << " : " << x << endl 14 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 15 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 16 | 17 | const ll MOD = 1e9 + 7; // 1000000007; 18 | 19 | /*---------------------------------------------------------------------------------------------------------------*/ 20 | 21 | void solve() 22 | { 23 | string s; 24 | cin >> s; 25 | int pos = 0; 26 | for (int i = 0; i < s.size(); i++) 27 | { 28 | if (s[i] >= 'A' && s[i] <= 'Z') 29 | { 30 | pos = i + 1; 31 | break; 32 | } 33 | } 34 | cout << pos << endl; 35 | 36 | } 37 | 38 | int main(void) 39 | { 40 | //efficient; 41 | 42 | int t=1; 43 | //cin>>t; 44 | while(t--) 45 | { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /CodeForces/1793 A. Yet Another Promotion.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios_base::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*---------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | ll a, b, n, m, ans = 0; 23 | cin >> a >> b; 24 | cin >> n >> m; 25 | 26 | ans = min(n*a, n*b); 27 | 28 | ll div = n/(m+1); 29 | ll rem = n%(m+1); 30 | 31 | ll promo = a*(div*m); 32 | promo = promo + min(rem*a, rem*b); 33 | ans = min(ans, promo); 34 | 35 | cout << ans << endl; 36 | } 37 | 38 | int main(void) 39 | { 40 | efficient; 41 | 42 | int t=1; 43 | cin>>t; 44 | while(t--) 45 | { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /CSES Problem Set/All IN ONE/1634. Minimizing Coins (Iterative Approach).cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef unsigned long long ull; 7 | 8 | #define endl '\n' 9 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 10 | 11 | /*---------------------------------------------------------------------------------------------------------------*/ 12 | 13 | void solve() 14 | { 15 | int n, total; 16 | cin >> n >> total; 17 | 18 | vector coins(n, 0); 19 | for (auto &u: coins) cin >> u; 20 | 21 | vector dp(total + 5, 1e9); 22 | 23 | // Base Case 24 | dp[0] = 0; 25 | 26 | for (int sum = 1; sum <= total; sum++) { // O(total) 27 | for (auto coin: coins) { // O(n) 28 | if (coin <= sum) { 29 | // Transition 30 | dp[sum] = min(dp[sum], dp[sum - coin] + 1); 31 | } 32 | } 33 | } 34 | 35 | cout << (dp[total] < 1e9 ? dp[total] : -1) << endl; 36 | } 37 | 38 | int main(void) { 39 | efficient(); 40 | 41 | solve(); 42 | 43 | return 0; 44 | // Every problem has its weakness. 45 | // This problem's weakness is...the existence of me! 46 | } -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/2. Minimizing Coins (Iterative Approach).cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef unsigned long long ull; 7 | 8 | #define endl '\n' 9 | #define efficient() ios_base::sync_with_stdio(0); cin.tie(0); 10 | 11 | /*---------------------------------------------------------------------------------------------------------------*/ 12 | 13 | void solve() 14 | { 15 | int n, total; 16 | cin >> n >> total; 17 | 18 | vector coins(n, 0); 19 | for (auto &u: coins) cin >> u; 20 | 21 | vector dp(total + 5, 1e9); 22 | 23 | // Base Case 24 | dp[0] = 0; 25 | 26 | for (int sum = 1; sum <= total; sum++) { // O(total) 27 | for (auto coin: coins) { // O(n) 28 | if (coin <= sum) { 29 | // Transition 30 | dp[sum] = min(dp[sum], dp[sum - coin] + 1); 31 | } 32 | } 33 | } 34 | 35 | cout << (dp[total] < 1e9 ? dp[total] : -1) << endl; 36 | } 37 | 38 | int main(void) { 39 | efficient(); 40 | 41 | solve(); 42 | 43 | return 0; 44 | // Every problem has its weakness. 45 | // This problem's weakness is...the existence of me! 46 | } -------------------------------------------------------------------------------- /CodeForces/1760 C. Advantage.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | ll n, x; 19 | cin >> n; 20 | 21 | vector v, temp; 22 | 23 | for (ll i=0; i> x; 26 | v.push_back(x); 27 | temp.push_back(x); 28 | } 29 | 30 | sort(temp.begin(), temp.end()); 31 | 32 | for (ll i=0; i>t; 52 | while(t--) 53 | { 54 | solve(); 55 | } 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 9-Square Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //void solve_1() 5 | //{ 6 | // int n; 7 | // cin >> n; 8 | // 9 | // double sq_root = sqrt(n); 10 | // 11 | // if(ceil(sq_root) == floor(sq_root)) 12 | // cout << "YES" << endl; 13 | // else 14 | // cout << "NO" << endl; 15 | // 16 | // // ceil() and floor() both function's return type is double/float. 17 | // // And comparing two double/float using '=', gives wrong answer some times. 18 | //} 19 | 20 | //void solve_2() 21 | //{ 22 | // int n; 23 | // cin >> n; 24 | // 25 | // double sq_root = sqrt(n); 26 | // double difference = ceil(sq_root) == floor(sq_root); 27 | // 28 | // if(difference < 0.00001) 29 | // cout << "YES" << endl; 30 | // else 31 | // cout << "NO" << endl; 32 | //} 33 | 34 | void solve_3() 35 | { 36 | int n; 37 | cin >> n; 38 | 39 | int sq_root = sqrt(n); 40 | 41 | if(sq_root * sq_root == n) 42 | cout << "YES" << endl; 43 | else 44 | cout << "NO" << endl; 45 | } 46 | 47 | int main(void) 48 | { 49 | int t; 50 | cin >> t; 51 | 52 | while(t--) 53 | { 54 | solve_3(); // Best solution is solve 3 and 2. solve 1 has some problem. 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /CodeForces/1473 A. Replacing Elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | solve() 7 | { 8 | int n, d; 9 | cin >> n >> d; 10 | 11 | int arr[n]; 12 | for (int i=0; i> arr[i]; 14 | 15 | sort(arr, arr+n); 16 | 17 | if (arr[n-1] <= d) 18 | cout << "YES" << endl; 19 | 20 | else 21 | { 22 | for (int i=n-1; i>=0; i--) 23 | { 24 | if(arr[i] <=d ) 25 | { 26 | cout << "YES" << endl; 27 | return 0; 28 | } 29 | 30 | else 31 | { 32 | for (int j=0; j> t; 56 | 57 | while(t--) 58 | { 59 | solve(); 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Dimik OJ (Part of LightOJ)/Problem 12-Factorial 100.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int two = 0, five = 0; 5 | 6 | void factorization(int n) // In bangla 'উৎপাদ = Factorization' 7 | { 8 | 9 | vector v; 10 | 11 | for (int i=2; i<=n; ) 12 | { 13 | if(n%i == 0) 14 | { 15 | n = n/i; 16 | v.push_back(i); 17 | if (i == 2) 18 | two = two + 1; 19 | else if(i == 5) 20 | five = five + 1; 21 | i = 2; 22 | } 23 | else 24 | i++; 25 | } 26 | //for (int i=0; i> t; 35 | 36 | while (t--) 37 | { 38 | int n; 39 | cin >> n; 40 | 41 | for (int i=2; i<=n; i++) 42 | factorization(i); 43 | //cout << "Two: " << two << ' ' << "Five: " << five << endl; 44 | 45 | if (two < five) 46 | { 47 | cout << two << endl; 48 | two = 0; 49 | } 50 | else 51 | { 52 | cout << five << endl; 53 | five = 0; 54 | } 55 | two = 0; 56 | five = 0; 57 | } 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /CodeForces/1689 B. Mystic Permutation.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; 19 | cin >> n; 20 | int arr[n+1], A[n+1]; 21 | 22 | for (int i=1; i<=n; i++) 23 | { 24 | cin >> arr[i]; 25 | A[i] = i; 26 | } 27 | 28 | if (n==1) 29 | { 30 | cout << "-1" << endl; 31 | return; 32 | } 33 | for (int i=1; i>t; 52 | while(t--) 53 | { 54 | solve(); 55 | } 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /LeetCode/3025. Find the Number of Ways to Place People I.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfPairs(vector>& points) { 4 | int n = (int) points.size(); 5 | int ans = 0; 6 | 7 | sort(points.begin(), points.end(), [](const vector& a, const vector& b) { 8 | if (a[0] == b[0]) 9 | return a[1] > b[1]; 10 | else 11 | return a[0] < b[0]; 12 | }); 13 | 14 | for (int one = n - 1; one >= 0; one--) { 15 | for (int two = one - 1; two >= 0; two--) { 16 | int x1 = points[one][0], y1 = points[one][1]; 17 | int x2 = points[two][0], y2 = points[two][1]; 18 | 19 | if (y2 < y1) continue; 20 | 21 | bool ok = true; 22 | for (int i = 0; i < n; i++) { 23 | if (i != one and i != two) { 24 | if ( (min(x1, x2) <= points[i][0] and points[i][0] <= max(x1, x2)) and 25 | (min(y1, y2) <= points[i][1] and points[i][1] <= max(y1, y2)) ) { 26 | ok = false; 27 | } 28 | } 29 | } 30 | if (ok) ans++; 31 | } 32 | } 33 | 34 | return ans; 35 | } 36 | }; -------------------------------------------------------------------------------- /CodeForces/1749 B. Death's Blessing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef vector vi; 6 | typedef pair pi; 7 | 8 | #define endl '\n' 9 | #define show(x) cout << #x << " : " << x << endl 10 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 11 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 12 | 13 | void solve() 14 | { 15 | ll n; 16 | cin >> n; 17 | ll a[n], b[n]; 18 | for (int i=0; i> a[i]; 20 | for (int i=0; i> b[i]; 22 | 23 | ll time = 0; 24 | for (int i=0; i>t; 53 | while(t--) 54 | { 55 | solve(); 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /CodeForces/1741 B. Funny Permutation.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | void solve() 17 | { 18 | int n; 19 | cin >> n; 20 | 21 | if (n==3) 22 | { 23 | cout << -1 << endl; 24 | return; 25 | } 26 | else if (n%2 == 0) 27 | { 28 | for (int i=n; i>(n/2); i--) 29 | cout << i << " "; 30 | 31 | for (int i=1; i<=(n/2); i++) 32 | cout << i << " "; 33 | } 34 | else 35 | { 36 | for (int i=n; i>(n/2)+1; i--) 37 | cout << i << " "; 38 | 39 | for (int i=1; i<=(n/2)+1; i++) 40 | cout << i << " "; 41 | } 42 | 43 | cout << endl; 44 | 45 | } 46 | 47 | int main(void) 48 | { 49 | //efficient; 50 | 51 | int t=1; 52 | cin>>t; 53 | while(t--) 54 | { 55 | solve(); 56 | } 57 | return 0; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /CodeForces/1730 A. Planets.cpp: -------------------------------------------------------------------------------- 1 | // In the name of Allah the merciful. 2 | #include 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | typedef vector vi; 7 | typedef pair pi; 8 | 9 | #define endl '\n' 10 | #define yes cout << "Yes" << endl 11 | #define no cout << "No" << endl 12 | #define show(x) cout << #x << " : " << x << endl 13 | #define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 14 | #define efficient ios::sync_with_stdio(0); cin.tie(0); 15 | 16 | const ll MOD = 1e9 + 7; // 1000000007; 17 | 18 | /*----------------------------------------------------------------------------------------------------------------------------------------------*/ 19 | 20 | void solve() 21 | { 22 | int n, c, ans = 0; 23 | cin >> n >> c; 24 | 25 | vector v(n); 26 | 27 | for(auto &i:v) 28 | cin >> i; 29 | 30 | vector freq(101, 0); 31 | 32 | for (int i=0; i>t; 49 | while(t--) 50 | { 51 | solve(); 52 | } 53 | return 0; 54 | } 55 | 56 | --------------------------------------------------------------------------------