├── .DS_Store ├── .gitignore ├── Code Forces ├── 1-A │ └── 1A Theatre-Square.cpp ├── 110-A │ └── 110A Nearly Lucky Number.cpp ├── 112-A │ └── 112A Petya and Strings.cpp ├── 116-A │ └── 116A Tram.cpp ├── 118-A │ └── 118A String-Task.cpp ├── 122-A │ └── 122A Lucky-Division.cpp ├── 131-A │ └── 131A cAPS-lOCK.cpp ├── 133-A │ └── 133A HQ9+.cpp ├── 136-A │ └── 136A Presents.cpp ├── 137-B │ └── 137B Permutation.cpp ├── 141-A │ └── 141A Amusing-Joke.cpp ├── 144-A │ └── 144A Arrival-of-the-General.cpp ├── 148-A │ └── 148A Insomnia-cure.cpp ├── 151-A │ ├── 151A Soft-Drinking(1).cpp │ └── 151A Soft-Drinking.cpp ├── 155-A │ └── 155A I_love_%username%.cpp ├── 158-A │ └── 158A Next-Round.cpp ├── 158-B │ └── 158B Taxi.cpp ├── 160-A │ └── 160A Twins.cpp ├── 189-A │ └── 189A Cut-Ribbon.cpp ├── 200-B │ └── 200B Drinks.cpp ├── 208-A │ └── 208A Dubstep.cpp ├── 231-A │ └── 231A Team.cpp ├── 236-A │ └── 236A Boy-or-Girl.cpp ├── 25-A │ └── 25A IQ-Test.cpp ├── 259-A │ └── 259A Little-Elephant-and-Chess.cpp ├── 263-A │ └── 263A Beautiful-Matrix.cpp ├── 266-A │ └── 266A Stones-on-the-Table.cpp ├── 266-B │ └── 266B Queue-at-the-School.cpp ├── 271-A │ └── 271A Beautiful-Year.cpp ├── 276-A │ └── 276A Lunch-Rush.cpp ├── 281-A │ └── 281A Word-Capitalization.cpp ├── 282-A │ └── 282A Bit++.cpp ├── 313-A │ └── 313A Ilya-and-Bank-Account.cpp ├── 318-A │ └── 318A Even-Odds.cpp ├── 320-A │ └── 320A Magic-Numbers.cpp ├── 327-A │ └── 327A Flipping-Game.cpp ├── 337-A │ └── 337A Puzzles.cpp ├── 339-A │ └── 339A Helpful-Maths.cpp ├── 339-B │ └── 339B Xenia-and-Ringroad.cpp ├── 344-A │ └── 344A Magnets.cpp ├── 384-A │ └── 384A Coder.cpp ├── 4-A │ └── 4A Watermelon.cpp ├── 4-C │ └── 4C Registration-system.cpp ├── 401-A │ └── 401A Vanya-and-Cards.cpp ├── 405-A │ └── 405A Gravity-Flip.cpp ├── 41-A │ └── 41A Translation.cpp ├── 432-A │ └── 432A Choosing-Teams.cpp ├── 451-A │ └── 451A Game-With-Sticks.cpp ├── 460-A │ └── 460A Vasya-and-Socks.cpp ├── 467-A │ └── 467A George-and-Accommodation.cpp ├── 467-B │ └── 467B Fedor-and-New-Game.cpp ├── 469-A │ └── 469A I-Wanna-Be-the-Guy.cpp ├── 472-A │ └── 472A Design-Tutorial-Learn-from-Math.cpp ├── 479-A │ └── 479A Expression.cpp ├── 486-A │ └── 486A Calculating-Function.cpp ├── 50-A │ └── 50A Domino-piling.cpp ├── 520-A │ └── 520A Pangram.cpp ├── 546-A │ └── 546A Soldier-and-Bananas.cpp ├── 58-A │ └── 58A Chat-room.cpp ├── 580-A │ └── 580A Kefa-and-First-Steps.cpp ├── 59-A │ └── 59A Word.cpp ├── 61-A │ └── 61A Ultra-Fast-Mathematician.cpp ├── 69-A │ └── 69A Young-Physicist.cpp ├── 705-A │ └── 705A Hulk.cpp ├── 71-A │ └── 71A Way-Too-Long-Words.cpp ├── 710-A │ └── 710A King Moves.cpp ├── 710-B │ └── 710B Optimal-Point-on-a-Line.cpp ├── 780-A │ └── 780A Andryusha-and-Socks.cpp ├── 784-A │ └── 784A Numbers-Joke.cpp ├── 884-A │ └── 884A Book Reading.cpp ├── 884-B │ └── 884B Japanese Crosswords Strike Back.cpp ├── 893-A │ └── 893A Chess For Three.cpp ├── 893-B │ └── 893B Beautiful Divisors.cpp ├── 894-A │ └── 894 QAQ.cpp ├── 898-B │ └── 898B Proper Nutrition.cpp ├── 900-A │ └── 900A Find Extra One.cpp ├── 900-B │ └── 900B Position in Fraction.cpp ├── 903-A │ └── 903A Hungry Student Problem.cpp ├── 903-B │ └── 903B The Modcrab.cpp ├── 903-C │ └── 903C Boxes Packing.cpp ├── 908-A │ └── 908A New Year and Counting Cards.cpp ├── 908-B │ └── 908B New Year and Buggy Bot.cpp ├── 908-C │ └── 908C New Year and Curling.cpp ├── 911-A │ └── 911A Nearest Minimums.cpp ├── 913-A │ └── 913A Modular Exponentiation.cpp ├── 915-B │ └── 915B Browser.cpp ├── 915-C │ └── 915C Permute Digits.cpp ├── 916-A │ └── 916A Jamie and Alarm Snooze.cpp ├── 918-A │ └── 918A Eleven.cpp ├── 918-B │ └── 918B Radio Station.cpp ├── 919-A │ └── 919A Supermarket.cpp ├── 919-B │ └── 919B Perfect Number.cpp ├── 919-C │ └── 919C Seat Arrangements.cpp ├── 920-A │ └── 920A Water The Garden.cpp ├── 920-B │ └── 920B Tea Queue.cpp ├── 920-C │ └── 920C Swap Adjacent Elements.cpp ├── 922-A │ └── 922A Cloning Toys.cpp ├── 922-B │ └── 922B Magic Forest.cpp ├── 938-A │ └── 938A Word Correction.cpp ├── 938-B │ └── 938B Run For Your Prize.cpp ├── 939-A │ └── 939A Love Triangle.cpp ├── 939-B │ └── 939B Hamster Farm.cpp └── 96-A │ └── 96A Football.cpp ├── LICENSE ├── LeetCode ├── Backspace-String-Compare.py ├── Best-Time-to-Buy-and-Sell-Stock-II.py ├── Contiguous-Array.py ├── Counting-Elements.py ├── Diameter-of-Binary-Tree.py ├── Group-Anagrams.py ├── Happy-Number.py ├── Last-Stone-Weight.py ├── Maximum-Subarray.py ├── Middle-of-the-Linked-List.py ├── Min-Stackpy.py ├── Move-Zeroes.py ├── Product-of-Array-Except-Self.py └── Single-Numbers.py └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canxkoz/Competitive-Programming/c5aba7ff3537e0ecb5cf0972e5b605498995e82a/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | Code Forces/.DS_Store 3 | -------------------------------------------------------------------------------- /Code Forces/1-A/1A Theatre-Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | long long n,m,a,prod1,prod2; 8 | cin >> n >> m >> a; 9 | if(n%a==0) 10 | prod1=n/a; 11 | else 12 | prod1=n/a+1; 13 | if(m%a==0) 14 | prod2=m/a; 15 | else 16 | prod2=m/a+1; 17 | cout << prod2*prod1; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Code Forces/110-A/110A Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long int luckycount=0,n,x; 7 | string s; 8 | cin >> s; 9 | n=s.length(); 10 | for(long long int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s1,s2; 7 | cin >> s1 >> s2; 8 | int l=s1.length(); 9 | char a,b; 10 | for(int i=0;ib) 25 | {cout << "1";return 0;} 26 | else 27 | {cout << "-1";return 0;} 28 | } 29 | } 30 | cout << "0"; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Code Forces/116-A/116A Tram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | int x,y; 10 | int sum=0,max=0; 11 | while(n--) 12 | { 13 | cin >> x >> y; 14 | sum=sum-x; 15 | sum=sum+y; 16 | max=max>sum?max:sum; 17 | } 18 | cout << max; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Code Forces/118-A/118A String-Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | string s; 9 | cin >> s; 10 | stringstream ss; 11 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int arr[13]={4,7,44,47,77,444,447,474,744,477,747,774,777} ; 7 | int x; 8 | cin >> x; 9 | for(int i=0;i<13;i++) 10 | { 11 | if(x%arr[i]==0) 12 | { 13 | cout << "YES"; 14 | return 0; 15 | } 16 | } 17 | cout << "NO"; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Code Forces/131-A/131A cAPS-lOCK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | int l=s.length(); 9 | int flag=1; 10 | for(int i=1;i 2 | 3 | using namespace std; 4 | int main(){ 5 | string s; 6 | cin >> s; 7 | int l=s.length(); 8 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int n,x; 6 | cin >> n; 7 | std::vector v(n); 8 | for(int i=1;i<=n;i++) 9 | { 10 | cin >> x; 11 | v[x-1]=i; 12 | } 13 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin >> n; 7 | int arr[5001]; 8 | for(int i=0;i<5001;i++) 9 | { 10 | arr[i]=0; 11 | } 12 | int x; 13 | for(int i=0;i> x; 16 | arr[x]++; 17 | } 18 | int count=0; 19 | for(int i=1;i<=n;i++) 20 | { 21 | if(arr[i]==0) 22 | { 23 | count++; 24 | } 25 | } 26 | cout << count; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Code Forces/141-A/141A Amusing-Joke.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | 5 | string s1,s2,s3; 6 | cin >> s1 >> s2 >> s3; 7 | int l1=s1.length(); 8 | int l2=s2.length(); 9 | int l3=s3.length(); 10 | int arr[27]; 11 | for(int i=0;i<27;i++) 12 | { 13 | arr[i]=0; 14 | } 15 | int x; 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | for(int i=0;i> arr[i]; 13 | } 14 | 15 | int mini=std::numeric_limits::max(),maxi=std::numeric_limits::min(),miniindex,maxiindex,swap; 16 | 17 | for(int i=0;imaxi) 25 | { 26 | maxi=arr[i]; 27 | maxiindex=i; 28 | } 29 | } 30 | if(maxiindex 2 | 3 | using namespace std; 4 | 5 | bool isdivisible(int k,int l,int m, int n, int d) 6 | { 7 | if(d%k==0||d%l==0||d%m==0||d%n==0) 8 | return true; 9 | else 10 | return false; 11 | } 12 | 13 | int main(){ 14 | int k,l,m,n,d; 15 | cin >> k >> l >> m >> n >> d; 16 | int count=0; 17 | for(int i=1;i<=d;i++) 18 | { 19 | if(isdivisible(k,l,m,n,i)) 20 | count++; 21 | } 22 | cout << count; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Code Forces/151-A/151A Soft-Drinking(1).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int mini(int x, int y, int z) 5 | { 6 | if(x<=y) 7 | { 8 | if(x<=z) 9 | return x; 10 | else if(z<=y) 11 | return z; 12 | else 13 | return y; 14 | } 15 | else 16 | { 17 | if(y<=z) 18 | return y; 19 | else 20 | return z; 21 | } 22 | } 23 | 24 | 25 | int main() { 26 | int n, k, l, c, d, p, nl, np; 27 | cin >> n >> k >> l >> c >> d >> p >> nl >> np; 28 | cout << mini(k*l/nl/n,c*d/n,p/np/n); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Code Forces/151-A/151A Soft-Drinking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int mini(int x, int y, int z) 5 | { 6 | if(x<=y) 7 | { 8 | if(x<=z) 9 | return x; 10 | else 11 | return z; 12 | } 13 | else 14 | { 15 | if(y<=z) 16 | return y; 17 | else 18 | return z; 19 | } 20 | } 21 | 22 | 23 | int main() { 24 | int n, k, l, c, d, p, nl, np; 25 | cin >> n >> k >> l >> c >> d >> p >> nl >> np; 26 | cout << mini(k*l/nl/n,c*d/n,p/np/n); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Code Forces/155-A/155A I_love_%username%.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | long long int n,k,max,min,count=0; 9 | cin >> n; 10 | cin >> k; 11 | max=k; 12 | min=k; 13 | n--; 14 | while(n--) 15 | { 16 | cin >> k; 17 | if(k>max) 18 | {count++;max=k;} 19 | if(k 2 | 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int n,k; 9 | cin >> n >> k; 10 | vector v(n); 11 | for(int i=0;i> v[i]; 14 | } 15 | int key; 16 | key=v[k-1]; 17 | int count=0; 18 | for(int i=0;i=key&&v[i]>0) 21 | count++; 22 | } 23 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int arr[5]; 9 | 10 | for(int i=0;i<5;i++) 11 | { 12 | arr[i]=0; 13 | } 14 | int x; 15 | 16 | while(n--) 17 | { 18 | cin >> x; 19 | arr[x]++; 20 | } 21 | int count=0; 22 | 23 | count+=arr[4]; 24 | 25 | 26 | if(arr[3]<=arr[1]) 27 | { 28 | count+=arr[3]; 29 | arr[1]=arr[1]-arr[3]; 30 | } 31 | else 32 | { 33 | arr[1]= 0; 34 | count = count + arr[3]; 35 | } 36 | 37 | 38 | if(arr[2]%2==0) 39 | { 40 | count = count + arr[2]/2; 41 | } 42 | else 43 | { 44 | count = count + arr[2]/2; 45 | arr[1]=arr[1]+2; 46 | } 47 | 48 | 49 | if(arr[1]%4==0) 50 | { 51 | count = count + arr[1]/4; 52 | } 53 | else 54 | { 55 | count = count + arr[1]/4 + 1; 56 | } 57 | 58 | cout << count; 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /Code Forces/160-A/160A Twins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin >> n; 7 | vector v(n); 8 | int sum=0,sum2=0; 9 | for(int i=0;i> v[i]; 12 | sum=sum+v[i]; 13 | } 14 | sort(v.rbegin(),v.rend()); 15 | for(int i=0;isum/2) 19 | { 20 | cout << i+1; 21 | return 0; 22 | } 23 | 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Code Forces/189-A/189A Cut-Ribbon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int32_t main() 5 | { 6 | int n,a,b,c; 7 | cin >> n >> a >> b >> c; 8 | 9 | int ans=0; 10 | 11 | for(int x=0;x*a<=n;x++) 12 | { 13 | for(int y=0;y*b<=n;y++) 14 | { 15 | if((n-x*a-y*b)%c==0) 16 | { 17 | int z = (n - x*a - y*b)/c; 18 | if(z>=0) 19 | { 20 | ans = max(ans,x+y+z); 21 | } 22 | } 23 | } 24 | } 25 | 26 | cout << ans; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Code Forces/200-B/200B Drinks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | double n; 6 | cin >> n; 7 | double sum=0,x; 8 | for(int i=0;i> x; 11 | sum+=x; 12 | } 13 | cout << setprecision(6) << fixed << sum/n; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Code Forces/208-A/208A Dubstep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | 8 | string s,s1; 9 | cin >> s; 10 | int l=s.length(); 11 | stringstream ss; 12 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int T; 9 | cin >> T; 10 | int count=0; 11 | int a,b,c; 12 | 13 | for(int i=0;i> a >> b >>c; 17 | 18 | if(a+b+c >1) 19 | { 20 | count=count+1; 21 | } 22 | } 23 | 24 | cout << count; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Code Forces/236-A/236A Boy-or-Girl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int arr[27]; 8 | for(int i=0;i<27;i++) 9 | { 10 | arr[i]=0; 11 | } 12 | string s; 13 | cin >> s; 14 | int x; 15 | int l=s.length(); 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | int oddc=0,evenc=0; 11 | for (int i = 0; i < n; ++i) 12 | { 13 | cin >> arr[i]; 14 | if(arr[i]%2) 15 | { 16 | oddc++; 17 | } 18 | else 19 | evenc++; 20 | } 21 | if(oddc==1) 22 | { 23 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | vector ChessBoard(8); 7 | for(int i=0;i<8;i++) 8 | { 9 | cin >> ChessBoard[i]; 10 | } 11 | for(int i=0;i<8;i++) 12 | { 13 | for(int j=0;j+1<8;j++) 14 | { 15 | if(ChessBoard[i][j]==ChessBoard[i][j+1]) 16 | { 17 | cout << "NO"; 18 | return 0; 19 | } 20 | } 21 | } 22 | cout << "YES"; 23 | 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Code Forces/263-A/263A Beautiful-Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int x; 7 | for(int i=0;i<5;i++) 8 | { 9 | for(int j=0;j<5;j++) 10 | { 11 | cin >> x; 12 | if(x) 13 | { 14 | cout << abs(i-2)+abs(j-2); 15 | return 0; 16 | } 17 | } 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Code Forces/266-A/266A Stones-on-the-Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int l; 7 | cin >> l; 8 | string s; 9 | cin >> s; 10 | int count=0; 11 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,t,i; 7 | cin >> n >> t; 8 | string s; 9 | cin >> s; 10 | while(t--) 11 | { 12 | i=0; 13 | while(i+1 2 | 3 | using namespace std; 4 | 5 | bool isdistinct(int n) 6 | { 7 | int a,b,c,d; 8 | a=n%10; 9 | n=n/10; 10 | b=n%10;n=n/10; 11 | c=n%10;n=n/10; 12 | d=n%10;n=n/10; 13 | if(a==b||a==c||a==d||b==c||b==d||c==d) 14 | { 15 | return false; 16 | } 17 | else 18 | { 19 | return true; 20 | } 21 | } 22 | 23 | int main(){ 24 | int n; 25 | cin >> n; 26 | n++; 27 | while(!isdistinct(n)) 28 | { 29 | n++; 30 | } 31 | cout << n; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Code Forces/276-A/276A Lunch-Rush.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int n,k; 7 | cin >> n >> k; 8 | int f,t; 9 | int maxi; 10 | cin >> f >> t; 11 | maxi=f; 12 | if(t>k) 13 | { 14 | maxi = f - (t-k); 15 | } 16 | for(int i=0;i> f >> t; 19 | if(t>k) 20 | { 21 | maxi = max( maxi, f-(t-k) ); 22 | } 23 | else 24 | { 25 | maxi = max( maxi, f); 26 | } 27 | } 28 | cout << maxi; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Code Forces/281-A/281A Word-Capitalization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | char c=s[0]; 9 | c=toupper(c); 10 | s[0]=c; 11 | cout << s; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Code Forces/282-A/282A Bit++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | string s; 10 | int x=0; 11 | 12 | for(int i=0;i> s; 15 | if(s[1]=='+') 16 | x=x+1; 17 | else 18 | x=x-1; 19 | } 20 | 21 | cout << x; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Code Forces/313-A/313A Ilya-and-Bank-Account.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int maximum(int a,int b,int c) 5 | { 6 | if(a>=b) 7 | { 8 | if(a>=c) 9 | return a; 10 | return c; 11 | } 12 | if(b>=c) 13 | return b; 14 | return c; 15 | } 16 | 17 | int deletelastdigit(int a) 18 | { 19 | int x=a/10; 20 | return x; 21 | } 22 | int deletedigitbeforelast(int a) 23 | { 24 | int x=a%10; 25 | int y=a/100; 26 | y=y*10+x; 27 | return y; 28 | } 29 | 30 | int main() 31 | { 32 | int n; 33 | cin >> n; 34 | cout << maximum(n,deletedigitbeforelast(n),deletelastdigit(n)); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Code Forces/318-A/318A Even-Odds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | long long n,k; 6 | cin >> n >> k; 7 | if(n%2==0) 8 | { 9 | if(k<=n/2) 10 | cout << 2*k-1; 11 | else 12 | cout << 2*(k)-n; 13 | } 14 | else 15 | { 16 | if(k<=n/2+1) 17 | cout << 2*k-1; 18 | else 19 | cout << (2*k-1)-n; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Code Forces/320-A/320A Magic-Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s; 7 | cin >> s; 8 | int l=s.length(); 9 | int i=0; 10 | while(i 2 | using namespace std; 3 | 4 | int32_t main() 5 | { 6 | int n; 7 | cin >> n; 8 | int arr[n]; 9 | int cumz[n]; 10 | int cumo[n]; 11 | 12 | cin >> arr[0]; 13 | 14 | if(arr[0]==0) 15 | { 16 | cumz[0]=1; 17 | cumo[0]=0; 18 | } 19 | else 20 | { 21 | cumo[0]=1; 22 | cumz[0]=0; 23 | } 24 | 25 | for(int i=1;i> arr[i]; 28 | if(arr[i]==0) 29 | { 30 | cumz[i]=1+cumz[i-1]; 31 | cumo[i]=cumo[i-1]; 32 | } 33 | else 34 | { 35 | cumo[i]=1+cumo[i-1]; 36 | cumz[i]=cumz[i-1]; 37 | } 38 | } 39 | 40 | 41 | int ans=0; 42 | int x; 43 | 44 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | 11 | int n,k; 12 | cin >> k >> n; 13 | vi v(n); 14 | for (int i = 0; i < n; i++) 15 | { 16 | cin >> v[i]; 17 | } 18 | sort(v.begin(),v.end()); 19 | int mini=v[n-1]-v[0]; 20 | for(int i=0;i+k-1 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | int l=s.length(); 9 | vector v; 10 | int x; 11 | for(int i=0;i 2 | using namespace std; 3 | #define ll long long 4 | 5 | 6 | int main() { 7 | 8 | ll n,m,x,y=1; 9 | cin >> n >> m; 10 | ll sum=0; 11 | for(ll it=0;it> x; 14 | if(x>=y) 15 | { 16 | sum = sum + x - y; 17 | 18 | } 19 | else 20 | { 21 | sum = sum + n + x - y; 22 | } 23 | y=x; 24 | 25 | } 26 | cout << sum; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Code Forces/344-A/344A Magnets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int n,count=0; 8 | cin >> n; 9 | int x,y; 10 | cin >> x; 11 | y=x; 12 | n--; 13 | while(n--) 14 | { 15 | cin >> x; 16 | if(x!=y) 17 | count++; 18 | y=x; 19 | } 20 | cout << count + 1; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Code Forces/384-A/384A Coder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | float n; 7 | cin >> n; 8 | cout << ceil(n*n/2) << endl; 9 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int a; 8 | cin >> a; 9 | if(a>3&&a%2==0) 10 | cout << "YES"; 11 | else 12 | cout << "NO"; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Code Forces/4-C/4C Registration-system.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int n; 8 | cin >> n; 9 | map m; 10 | string s; 11 | for(int i=0;i> s; 14 | map::iterator itr; 15 | itr=m.find(s); 16 | if(itr==m.end()) 17 | { 18 | cout << "OK\n"; 19 | m.insert(make_pair(s,1)); 20 | } 21 | else 22 | { 23 | int x=itr->second; 24 | cout << s << x << "\n"; 25 | x++; 26 | m.erase(s); 27 | m.insert(make_pair(s,x)); 28 | } 29 | } 30 | return 0; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Code Forces/401-A/401A Vanya-and-Cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | int x; 10 | cin >> x; 11 | int y=0,a; 12 | for(int i=0;i> a; 15 | y+=a; 16 | } 17 | y=abs(y); 18 | int ans=y/x; 19 | if(y%x!=0) 20 | ans++; 21 | cout << ans; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Code Forces/405-A/405A Gravity-Flip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define uint unsigned long long 5 | #define real long double 6 | 7 | int32_t main() 8 | { 9 | int n; 10 | cin >> n; 11 | int arr[n]; 12 | 13 | for(int i=0;i> arr[i]; 16 | } 17 | 18 | sort(arr,arr+n); 19 | 20 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | bool isdivisible(int k,int l,int m, int n, int d) 6 | { 7 | if(d%k==0||d%l==0||d%m==0||d%n==0) 8 | return true; 9 | else 10 | return false; 11 | } 12 | 13 | int main() 14 | { 15 | string s1,s2; 16 | cin >> s1 >> s2; 17 | reverse(s1.begin(),s1.end()); 18 | if(s1==s2) 19 | { 20 | cout << "YES"; 21 | } 22 | else 23 | { 24 | cout << "NO"; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Code Forces/432-A/432A Choosing-Teams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int n,x; 7 | cin >> n; 8 | int k; 9 | cin >> k; 10 | vector v(n); 11 | int count=0; 12 | for(int i=0;i> x; 15 | v[i] = x + k; 16 | if(x+k<=5) 17 | count++; 18 | } 19 | cout << count/3; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Code Forces/451-A/451A Game-With-Sticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n,m; 6 | cin >> n >> m; 7 | int x=min(n,m); 8 | if(x%2==0) 9 | cout << "Malvika"; 10 | else 11 | cout << "Akshat"; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Code Forces/460-A/460A Vasya-and-Socks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,m; 7 | cin >> n >> m; 8 | int count=0; 9 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | long long int n,x,y,count=0; 8 | cin >> n; 9 | while(n--) 10 | { 11 | cin >> x >> y; 12 | if(y-x>=2) 13 | { 14 | count++; 15 | } 16 | } 17 | cout << count; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Code Forces/467-B/467B Fedor-and-New-Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | using namespace std; 5 | 6 | 7 | bool solve(int a,int b,int n,int k) 8 | { 9 | int count=0; 10 | int arem,brem; 11 | int i=0; 12 | while(i> n >> m >> k; 32 | vector v(m); 33 | for(int i=0;i> v[i]; 36 | } 37 | int x, occurances=0; 38 | cin >> x; 39 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int n,p,q,prod=1; 8 | cin >> n; 9 | int arr[n+1]; 10 | 11 | for(int i=0;i> p; 17 | int x; 18 | for(int i=0;i> x; 21 | arr[x]=1; 22 | } 23 | cin >> q; 24 | for(int i=0;i> x; 27 | arr[x]=1; 28 | } 29 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | bool IsPrime( int number ) 10 | { 11 | if ( ( (!(number & 1)) && number != 2 ) || (number < 2) || (number % 3 == 0 && number != 3) ) 12 | { 13 | return (false); 14 | } 15 | for( int k = 1; 36*k*k-12*k < number;++k) 16 | { 17 | if ( (number % (6*k+1) == 0) || (number % (6*k-1) == 0) ) 18 | { 19 | return (false); 20 | } 21 | } 22 | return true; 23 | } 24 | 25 | 26 | int main() { 27 | 28 | int n; 29 | cin >> n; 30 | int flag=1; 31 | for(int i=4;i 2 | using namespace std; 3 | 4 | int minimum(int a,int b,int c) 5 | { 6 | if(a<=b) 7 | { 8 | if(a<=c) 9 | return a; 10 | return c; 11 | } 12 | if(b<=c) 13 | return b; 14 | return c; 15 | } 16 | 17 | 18 | 19 | int main() 20 | { 21 | int a,b,c; 22 | cin >> a >> b >> c; 23 | int d=a+b+c; 24 | int e=a*b+c; 25 | int f=a+b*c; 26 | int g=a*b*c; 27 | int h=(a+b)*c; 28 | int i=a*(b+c); 29 | cout << max((max((max(max(max(h,i),d),e)),f)),g); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Code Forces/486-A/486A Calculating-Function.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | long long int n; 8 | cin >> n; 9 | if(n%2==0) 10 | { 11 | cout << n/2; 12 | } 13 | else 14 | { 15 | cout << ((n/2) + 1)*-1; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Code Forces/50-A/50A Domino-piling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int m,n; 8 | cin >> m >> n; 9 | cout << m*n/2; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Code Forces/520-A/520A Pangram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | string s; 10 | cin >> s; 11 | int x; 12 | int arr[26]={0}; 13 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | long long int k,n,w,sum; 8 | cin >> k >> n >> w; 9 | sum = (k*(w+1)*(w))/2; 10 | 11 | if(sum-n>=0) 12 | { 13 | cout << sum-n; 14 | } 15 | else 16 | { 17 | cout << "0"; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Code Forces/58-A/58A Chat-room.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | string s; 8 | cin >> s; 9 | int l=s.length(); 10 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | bool isdivisible(int k,int l,int m, int n, int d) 6 | { 7 | if(d%k==0||d%l==0||d%m==0||d%n==0) 8 | return true; 9 | else 10 | return false; 11 | } 12 | 13 | int main(){ 14 | long long int x,y,n,count=1,max=1; 15 | cin >> n; 16 | cin >> y; 17 | n--; 18 | while(n--) 19 | { 20 | cin >> x; 21 | if(xcount?max:count; 26 | y=x; 27 | } 28 | cout << max; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Code Forces/59-A/59A Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | string s; 8 | cin >> s; 9 | int l=s.length(); 10 | int upc=0,lc=0; 11 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | string s1,s2; 6 | cin >> s1 >> s2; 7 | int l=s1.length(); 8 | int x,y,z; 9 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long int n,si=0,sj=0,sk=0,i,j,k; 7 | cin >> n; 8 | while(n--) 9 | { 10 | cin >> i >> j >> k; 11 | si=si+i; 12 | sj+=j; 13 | sk+=k; 14 | } 15 | if(si==0&&sj==0&&sk==0) 16 | { 17 | cout << "YES"; 18 | } 19 | else 20 | { 21 | cout << "NO"; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Code Forces/705-A/705A Hulk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | cout << "I "; 10 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | for(int i=0;i> s; 12 | if(s.length()>10) 13 | { 14 | stringstream ss; 15 | int l; 16 | l=s.length()-2; 17 | ss << s[0] << l << s[s.length()-1]; 18 | cout << ss.str() << endl; 19 | } 20 | else 21 | cout << s << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Code Forces/710-A/710A King Moves.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | if(s[0]>='b'&&s[0]<='g'&&s[1]>='2'&&s[1]<='7') 10 | { 11 | cout << "8"; 12 | return 0; 13 | } 14 | else if(s=="a1"||s=="a8"||s=="h1"||s=="h8") 15 | { 16 | cout << "3"; 17 | return 0; 18 | } 19 | else 20 | { 21 | cout << "5"; 22 | return 0; 23 | } 24 | 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Code Forces/710-B/710B Optimal-Point-on-a-Line.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | 5 | int main() { 6 | ll n; 7 | cin >> n; 8 | vector < ll > v(n); 9 | for(int i=0;i> v[i]; 12 | } 13 | 14 | sort(v.begin(),v.end()); 15 | ll p; 16 | if(n&1) 17 | p=n/2; 18 | else 19 | p=n/2-1; 20 | cout << v[p]; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Code Forces/780-A/780A Andryusha-and-Socks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | bool arr[100001]; 7 | for(int i=0;i,i<100001;i++) 8 | { 9 | arr[i]=false; 10 | } 11 | int n; 12 | cin >> n; 13 | int x; 14 | int count=0; 15 | int maxcount=0; 16 | for(int i=0;i<2*n;i++) 17 | { 18 | cin >> x; 19 | if(arr[x]==true) 20 | { 21 | arr[x]=false; 22 | count--; 23 | } 24 | else 25 | { 26 | count++; 27 | maxcount=max(maxcount,count); 28 | 29 | arr[x]=true; 30 | } 31 | 32 | } 33 | 34 | cout << maxcount; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Code Forces/784-A/784A Numbers-Joke.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | int arr[30]={ 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645}; 9 | int n; 10 | cin >> n; 11 | cout< 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int n,t; 7 | cin >> n >> t; 8 | int sum=0; 9 | int x; 10 | int count = 0; 11 | int flag = 1; 12 | for(int i=0;i> x; 15 | count++; 16 | sum = sum +(86400-x); 17 | if(sum>=t) 18 | flag=0; 19 | } 20 | cout << count; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Code Forces/884-B/884B Japanese Crosswords Strike Back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int n,k; 7 | cin >> n >> k; 8 | int sum=n-1; 9 | int x; 10 | for(int i=0;i>x; 13 | sum = sum +x; 14 | } 15 | if(sum==k) 16 | cout << "YES"; 17 | else 18 | cout << "NO"; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Code Forces/893-A/893A Chess For Three.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | int x=1,y=2,z=3,store,n,input; 11 | cin >> n; 12 | int flag=1; 13 | while(n--&&flag) 14 | { 15 | cin >> input; 16 | if(input==x) 17 | { 18 | store=y; 19 | y=z; 20 | z=store; 21 | } 22 | else if(input==y) 23 | { 24 | store=x; 25 | x=z; 26 | z=store; 27 | } 28 | else 29 | { 30 | flag=0; 31 | } 32 | } 33 | if(flag) 34 | { 35 | cout << "YES"; 36 | } 37 | else 38 | { 39 | cout << "NO"; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Code Forces/893-B/893B Beautiful Divisors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | int arr[10] = {1,6,28,120,496,2016,8128,32640,130816,523776}; 11 | int n; 12 | cin >> n; 13 | int flag=1; 14 | for(int i=9;i>=0&&flag;i--) 15 | { 16 | if(n%arr[i]==0) 17 | { 18 | cout << arr[i]; 19 | flag=0; 20 | } 21 | } 22 | 23 | return 0; 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Code Forces/894-A/894 QAQ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | string s; 9 | cin >> s; 10 | int l=s.length(); 11 | int count=0; 12 | 13 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | int main() 7 | { 8 | 9 | int n,a,b,x; 10 | cin >> n >> a >> b; 11 | 12 | for(int i=0;n>=0;i++) 13 | { 14 | 15 | if((n%b)==0) 16 | { 17 | cout << "YES\n"; 18 | cout << i << " " << n/b; 19 | return 0; 20 | } 21 | n=n-a; 22 | } 23 | 24 | cout << "NO"; 25 | return 0; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Code Forces/900-A/900A Find Extra One.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | int x,y,n; 8 | cin >> n; 9 | int posit=0,negat=0,onl=0; 10 | while(n--) 11 | { 12 | cin >> x >> y; 13 | if(x>0) 14 | posit++; 15 | if(x<0) 16 | negat++; 17 | if(x==0) 18 | onl++; 19 | 20 | } 21 | if(posit<=1||negat<=1&&onl==0) 22 | { 23 | cout << "Yes";return 0; 24 | } 25 | if(onl>1) 26 | { 27 | cout << "No";return 0; 28 | } 29 | if(onl==1&&posit==0||negat==0) 30 | { 31 | cout << "Yes";return 0; 32 | } 33 | cout << "No"; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Code Forces/900-B/900B Position in Fraction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | long long a,b,c,quo; 11 | cin >> a >> b >> c; 12 | for(int i=0;i<=100000;i++) 13 | { 14 | a=a*10; 15 | quo=a/b; 16 | if(quo==c) 17 | { 18 | cout << i+1;return 0; 19 | } 20 | a=a%b; 21 | } 22 | 23 | cout << "-1"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Code Forces/903-A/903A Hungry Student Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | vi v; 13 | int x; 14 | bool arr[101]={false}; 15 | int i=0,j=0; 16 | for(i=0;i<35;i++) 17 | { 18 | for(j=0;j<16&&3*i+7*j<101;j++) 19 | { 20 | arr[3*i+7*j]=true; 21 | } 22 | } 23 | for(int i=0;i> x; 26 | if(arr[x]) 27 | cout << "YES\n"; 28 | else 29 | cout << "NO\n"; 30 | 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Code Forces/903-B/ 903B The Modcrab.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | 11 | int h1,a1,c1; 12 | cin >> h1 >> a1 >> c1; 13 | int h2,a2; 14 | cin >> h2 >> a2; 15 | vector v; 16 | for(int i=0;h2>0&&h1>0;i++) 17 | { 18 | if(h1-a2<=0&&h2-a1>0) 19 | { 20 | v.push_back("HEAL"); 21 | h1=h1+c1; 22 | } 23 | else 24 | { 25 | v.push_back("STRIKE"); 26 | h2=h2-a1; 27 | } 28 | h1=h1-a2; 29 | } 30 | cout << v.size() << "\n"; 31 | int l=v.size(); 32 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define lli long long int 5 | #define vi vector 6 | #define vlli vector 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | vi v(n); 13 | for(int i=0;i> v[i]; 16 | } 17 | sort(v.begin(),v.end()); 18 | int count=0,max=0; 19 | int key=v[0]; 20 | for(int i=0;icount?max:count; 26 | key=v[i]; 27 | } 28 | else 29 | { 30 | count=1; 31 | key=v[i]; 32 | } 33 | } 34 | cout << max; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Code Forces/908-A/908A New Year and Counting Cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ll long long 6 | 7 | void scanvector(vector &vec,int reqdsiz) 8 | { 9 | for(int i=0;i> vec[i]; 12 | } 13 | } 14 | 15 | void printvector(vector &v) 16 | { 17 | int l=v.size(); 18 | for(int i=0;i> s; 28 | int l=s.length(); 29 | int count=0; 30 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | #define ll long long 6 | 7 | struct pointer 8 | { 9 | int i; 10 | int j; 11 | }; 12 | 13 | pointer Down(pointer a) 14 | { 15 | a.i++; 16 | return a; 17 | } 18 | pointer Right(pointer a) 19 | { 20 | a.j++; 21 | return a; 22 | } 23 | pointer Up(pointer a) 24 | { 25 | a.i--; 26 | return a; 27 | } 28 | pointer Left(pointer a) 29 | { 30 | a.j--; 31 | return a; 32 | } 33 | 34 | int direction(vector &maze,int n,int m,pointer start,pointer end,string ans) 35 | { 36 | string keys="DLRU"; 37 | char c1,c2,c3,c4; 38 | int count=0; 39 | int found; 40 | for(int keys_i=1;keys_i<25;keys_i++) 41 | { 42 | c1=keys[0]; 43 | c2=keys[1]; 44 | c3=keys[2]; 45 | c4=keys[3]; 46 | pointer st=start; 47 | found=1; 48 | for(int j=0;j=n) 96 | { 97 | found=0; 98 | } 99 | else if(st.j<0||st.j>=m) 100 | { 101 | found=0; 102 | } 103 | else if(maze[st.i][st.j]=='#') 104 | { 105 | found=0; 106 | } 107 | else if(maze[st.i][st.j]=='E') 108 | { 109 | count++; 110 | found=0; 111 | } 112 | 113 | 114 | } 115 | 116 | next_permutation(keys.begin(),keys.end()); 117 | } 118 | return count; 119 | } 120 | 121 | 122 | 123 | 124 | 125 | int main() 126 | { 127 | pointer start,end; 128 | int n,m; 129 | cin >> n >> m; 130 | vector maze(n); 131 | for(int i=0;i> maze[i]; 134 | } 135 | 136 | for(int i=0;i> s; 155 | 156 | cout << direction(maze,n,m,start,end,s); 157 | 158 | return 0; 159 | } 160 | -------------------------------------------------------------------------------- /Code Forces/908-C/908C New Year and Curling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ld long double 6 | #define ll long long 7 | 8 | ld height(ld r,ld d1,ld d2) 9 | { 10 | return sqrt(abs(4*r*r-(d1-d2)*(d1-d2))); 11 | } 12 | struct circle 13 | { 14 | ld ci; 15 | ld cj; 16 | }; 17 | 18 | 19 | int main() 20 | { 21 | int n,r; 22 | cin >> n >> r; 23 | vector v(n); 24 | vector hei(n); 25 | for(int i=0;i> v[i]; 28 | } 29 | 30 | for(int i=0;i 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | 9 | int n,x; 10 | cin >> n; 11 | int curr=numeric_limits::max(); 12 | int pos,ans=numeric_limits::max(); 13 | for(int i=0;i> x; 16 | if(x::max(); 21 | } 22 | else if(x==curr) 23 | { 24 | ans=min(ans,i-pos); 25 | pos=i; 26 | } 27 | } 28 | cout << ans; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Code Forces/913-A/913A Modular Exponentiation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | ll powe(ll a, ll n) 7 | { 8 | ll ret = 1; 9 | while(n) 10 | { 11 | if(n%2 == 1) ret *= a; 12 | a *= a; n /= 2; 13 | } 14 | return ret; 15 | } 16 | 17 | int main() 18 | { 19 | ll n,m; 20 | cin >> n >> m; 21 | 22 | if(n>=63) 23 | { 24 | cout << m; 25 | return 0; 26 | } 27 | else 28 | { 29 | cout << m%(powe(2,n)); 30 | } 31 | 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Code Forces/915-B/915B Browser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | int n,pos,l,r; 9 | cin >> n >> pos >> l >> r; 10 | 11 | int count=0; 12 | 13 | bool left=true; 14 | bool right=true; 15 | 16 | if(l==1) 17 | { 18 | left=false; 19 | } 20 | 21 | if(r==n) 22 | { 23 | right=false; 24 | } 25 | 26 | if(left&&pos-l<=r-pos) 27 | { 28 | count+=abs(pos-l); 29 | count++; 30 | pos=l; 31 | left=false; 32 | } 33 | if(right&&pos-l>r-pos) 34 | { 35 | count+=abs(r-pos); 36 | count++; 37 | pos=r; 38 | right=false; 39 | } 40 | 41 | if(left) 42 | { 43 | count+=abs(pos-l); 44 | count++; 45 | pos=l; 46 | 47 | } 48 | 49 | if(right) 50 | { 51 | count+=abs(r-pos); 52 | count++; 53 | pos=r; 54 | } 55 | 56 | 57 | cout << count; 58 | 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /Code Forces/915-C/915C Permute Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | int n,k; 9 | cin >> n >> k; 10 | vector v(n); 11 | for(int i=0;i> v[i]; 14 | } 15 | sort(v.rbegin(),v.rend()); 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool hundr(int x) 5 | { 6 | x=x/10; 7 | if(x%10==7) 8 | return true; 9 | return false; 10 | } 11 | 12 | int main() 13 | { 14 | int n,hh,mm; 15 | cin >> n >> hh >> mm; 16 | int count=0; 17 | while(1) 18 | { 19 | if(mm%10==7||hh%10==7||hundr(mm)||hundr(hh)) 20 | { 21 | cout << count; 22 | return 0; 23 | } 24 | else 25 | { 26 | mm = mm - n; 27 | count++; 28 | if(mm<0) 29 | { 30 | mm = mm + 60; 31 | hh--; 32 | } 33 | 34 | if(hh<0) 35 | { 36 | hh=23; 37 | } 38 | } 39 | } 40 | 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Code Forces/918-A/918A Eleven.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | 7 | 8 | int32_t main() 9 | { 10 | int fib[100]; 11 | fib[0]=0; 12 | fib[1]=1; 13 | fib[2]=1; 14 | for(int i=3;fib[i-1]<=1000;i++) 15 | { 16 | fib[i]=fib[i-1]+fib[i-2]; 17 | } 18 | int n; 19 | cin >> n; 20 | int counter=2; 21 | for(int i=1;i<=n;i++) 22 | { 23 | if(i==fib[counter]) 24 | { 25 | counter++; 26 | cout << "O"; 27 | } 28 | else 29 | { 30 | cout << "o"; 31 | } 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Code Forces/918-B/918B Radio Station.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | struct ip 7 | { 8 | int a; 9 | int b; 10 | int c; 11 | int d; 12 | }; 13 | 14 | struct command 15 | { 16 | string comm; 17 | ip address; 18 | }; 19 | 20 | bool so(command x,command y) 21 | { 22 | if(x.address.a==y.address.a) 23 | { 24 | if(x.address.b==y.address.b) 25 | { 26 | if(x.address.c==y.address.c) 27 | { 28 | return x.address.d v,int low,int high,command key) 38 | { 39 | while(low<=high) 40 | { 41 | int mid = (high+low)/2; 42 | 43 | if(v[mid].address.a==key.address.a) 44 | { 45 | if(v[mid].address.b==key.address.b) 46 | { 47 | if(v[mid].address.c==key.address.c) 48 | { 49 | if(v[mid].address.d==key.address.d) 50 | { 51 | return v[mid].comm; 52 | } 53 | else if(v[mid].address.d> n >> m; 105 | 106 | vector v(n); 107 | 108 | char ch; 109 | string s; 110 | 111 | command ans; 112 | 113 | for(int i=0;i> v[i].comm; 116 | cin >> v[i].address.a; 117 | cin >> ch; 118 | cin >> v[i].address.b; 119 | cin >> ch; 120 | cin >> v[i].address.c; 121 | cin >> ch; 122 | cin >> v[i].address.d; 123 | 124 | } 125 | 126 | sort(v.begin(),v.end(),so); 127 | 128 | for(int i=0;i> s; 131 | cout << s << " "; 132 | cin >> ans.address.a; 133 | cout << ans.address.a; 134 | cin >> ch; 135 | cout << ch; 136 | cin >> ans.address.b; 137 | cout << ans.address.b; 138 | cin >> ch; 139 | cout << ch; 140 | cin >> ans.address.c; 141 | cout << ans.address.c; 142 | cin >> ch; 143 | cout << ch; 144 | cin >> ans.address.d; 145 | cout << ans.address.d; 146 | cin >> ch; 147 | cout << ch; 148 | cout << " #"; 149 | cout << binarysearch(v,0,n-1,ans); 150 | cout << "\n"; 151 | } 152 | 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /Code Forces/919-A/919A Supermarket.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | int32_t main() 7 | { 8 | 9 | int n,m; 10 | cin >> n >> m; 11 | 12 | long double a,b,ans=numeric_limits::max(); 13 | while(n--) 14 | { 15 | cin >> a >> b; 16 | ans = min(ans,a/b); 17 | } 18 | cout << fixed << setprecision(10) << ans*m; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Code Forces/919-B/919B Perfect Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool perfect(int n) 7 | { 8 | int sum=0; 9 | while(n>0) 10 | { 11 | sum+=n%10; 12 | n=n/10; 13 | } 14 | if(sum==10) 15 | return true; 16 | else 17 | return false; 18 | } 19 | 20 | 21 | int32_t main() 22 | { 23 | 24 | int count=0; 25 | int i=1; 26 | int ans=0; 27 | int k; 28 | cin >> k; 29 | while(count 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | int32_t main() 7 | { 8 | 9 | int n,m,k; 10 | cin >> n >> m >>k; 11 | vector v(n); 12 | for(int i=0;i> v[i]; 15 | } 16 | 17 | int ans=0,dotcount=0; 18 | 19 | for(int i=0;i=k) 28 | ans++; 29 | } 30 | else 31 | { 32 | dotcount=0; 33 | } 34 | } 35 | } 36 | 37 | if(k!=1) 38 | { 39 | for(int j=0;j=k) 48 | ans++; 49 | } 50 | else 51 | { 52 | dotcount=0; 53 | } 54 | } 55 | } 56 | } 57 | 58 | cout << ans; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /Code Forces/920-A/920A Water The Garden.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | #define trace1(x) cerr<<#x<<": "<=0) 29 | { 30 | if(initialarr[i-1]==0) 31 | { 32 | if(arr[i-1]!=1) 33 | { 34 | arr[i-1]=1; 35 | cnt++; 36 | 37 | } 38 | 39 | } 40 | } 41 | if(i+1> t; 65 | while(t--) 66 | { 67 | int n,k; 68 | cin >> n >> k; 69 | for(int i=0;i> x; 79 | arr[x-1]=1; 80 | } 81 | int t=1; 82 | while(count 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | #define trace1(x) cerr<<#x<<": "<> t; 23 | while(t--) 24 | { 25 | int n; 26 | cin >> n; 27 | int timecount=0; 28 | student arr[n]; 29 | int ans[n]; 30 | 31 | for(int i=0;i> arr[i].l >> arr[i].r; 34 | arr[i].index=i; 35 | } 36 | vector v(n); 37 | v.clear(); 38 | 39 | int start=0; 40 | int count=0; 41 | 42 | while(count 2 | using namespace std; 3 | 4 | #define int long long 5 | #define uint unsigned long long 6 | #define real long double 7 | #define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 8 | #define endl "\n" 9 | #define ss second 10 | #define ff first 11 | #define pb push_back 12 | #define all(x) x.begin(),x.end() 13 | #define rall(x) x.rbegin(),x.rend() 14 | 15 | #define mod 1000000007 16 | 17 | 18 | #define trace1(x) cerr<<#x<<": "<> n; 29 | int arr[n]; 30 | for (int i = 0; i < n; ++i) 31 | { 32 | /* code */ 33 | cin >> arr[i]; 34 | } 35 | string s; 36 | cin >> s; 37 | 38 | for(int i=0;i 2 | using namespace std; 3 | 4 | int32_t main() 5 | { 6 | int x,y; 7 | cin >> x >> y; 8 | int ncopy=y-1; 9 | int rem=x-ncopy; 10 | if(x==0&&y==0) 11 | { 12 | cout << "No"; 13 | return 0; 14 | } 15 | if(x==0&&y==1) 16 | { 17 | cout << "Yes"; 18 | return 0; 19 | } 20 | if(x=1) 26 | { 27 | cout << "Yes"; 28 | return 0; 29 | } 30 | 31 | cout << "No"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Code Forces/922-B/922B Magic Forest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int32_t main() 5 | { 6 | //I know it does not makes sense but this is the "FASTEST" way. 7 | int n; 8 | cin >> n; 9 | int arr[2501] = {0,0,0,0,0,0,1,1,1,1,2,2,5,7,10,10,10,10,11,11,14,16,19,19,26,32,39,43,52,58,65,65,65,65,66,66,69,71,74,74,81,87,94,98,107,113,120,120,135,149,164,176,193,207,222,230,251,269,288,300,321,335,350,350,350,350,351,351,354,356,359,359,366,372,379,383,392,398,405,405,420,434,449,461,478,492,507,515,536,554,573,585,606,620,635,635,666,696,727,755,788,818,849,873,910,944,979,1007,1044,1074,1105,1121,1166,1208,1251,1287,1332,1370,1409,1433,1482,1524,1567,1595,1640,1670,1701,1701,1701,1701,1702,1702,1705,1707,1710,1710,1717,1723,1730,1734,1743,1749,1756,1756,1771,1785,1800,1812,1829,1843,1858,1866,1887,1905,1924,1936,1957,1971,1986,1986,2017,2047,2078,2106,2139,2169,2200,2224,2261,2295,2330,2358,2395,2425,2456,2472,2517,2559,2602,2638,2683,2721,2760,2784,2833,2875,2918,2946,2991,3021,3052,3052,3115,3177,3240,3300,3365,3427,3490,3546,3615,3681,3748,3808,3877,3939,4002,4050,4127,4201,4276,4344,4421,4491,4562,4618,4699,4773,4848,4908,4985,5047,5110,5142,5235,5325,5416,5500,5593,5679,5766,5838,5935,6025,6116,6192,6285,6363,6442,6490,6595,6693,6792,6876,6977,7063,7150,7206,7311,7401,7492,7552,7645,7707,7770,7770,7770,7770,7771,7771,7774,7776,7779,7779,7786,7792,7799,7803,7812,7818,7825,7825,7840,7854,7869,7881,7898,7912,7927,7935,7956,7974,7993,8005,8026,8040,8055,8055,8086,8116,8147,8175,8208,8238,8269,8293,8330,8364,8399,8427,8464,8494,8525,8541,8586,8628,8671,8707,8752,8790,8829,8853,8902,8944,8987,9015,9060,9090,9121,9121,9184,9246,9309,9369,9434,9496,9559,9615,9684,9750,9817,9877,9946,10008,10071,10119,10196,10270,10345,10413,10490,10560,10631,10687,10768,10842,10917,10977,11054,11116,11179,11211,11304,11394,11485,11569,11662,11748,11835,11907,12004,12094,12185,12261,12354,12432,12511,12559,12664,12762,12861,12945,13046,13132,13219,13275,13380,13470,13561,13621,13714,13776,13839,13839,13966,14092,14219,14343,14472,14598,14725,14845,14978,15108,15239,15363,15496,15622,15749,15861,16002,16140,16279,16411,16552,16686,16821,16941,17086,17224,17363,17487,17628,17754,17881,17977,18134,18288,18443,18591,18748,18898,19049,19185,19346,19500,19655,19795,19952,20094,20237,20349,20518,20680,20843,20991,21156,21306,21457,21577,21746,21900,22055,22179,22336,22462,22589,22653,22842,23028,23215,23395,23584,23766,23949,24117,24310,24496,24683,24855,25044,25218,25393,25537,25738,25932,26127,26307,26504,26686,26869,27021,27222,27408,27595,27751,27940,28098,28257,28353,28570,28780,28991,29187,29400,29598,29797,29965,30182,30384,30587,30759,30964,31138,31313,31425,31650,31860,32071,32251,32464,32646,32829,32949,33166,33352,33539,33663,33852,33978,34105,34105,34105,34105,34106,34106,34109,34111,34114,34114,34121,34127,34134,34138,34147,34153,34160,34160,34175,34189,34204,34216,34233,34247,34262,34270,34291,34309,34328,34340,34361,34375,34390,34390,34421,34451,34482,34510,34543,34573,34604,34628,34665,34699,34734,34762,34799,34829,34860,34876,34921,34963,35006,35042,35087,35125,35164,35188,35237,35279,35322,35350,35395,35425,35456,35456,35519,35581,35644,35704,35769,35831,35894,35950,36019,36085,36152,36212,36281,36343,36406,36454,36531,36605,36680,36748,36825,36895,36966,37022,37103,37177,37252,37312,37389,37451,37514,37546,37639,37729,37820,37904,37997,38083,38170,38242,38339,38429,38520,38596,38689,38767,38846,38894,38999,39097,39196,39280,39381,39467,39554,39610,39715,39805,39896,39956,40049,40111,40174,40174,40301,40427,40554,40678,40807,40933,41060,41180,41313,41443,41574,41698,41831,41957,42084,42196,42337,42475,42614,42746,42887,43021,43156,43276,43421,43559,43698,43822,43963,44089,44216,44312,44469,44623,44778,44926,45083,45233,45384,45520,45681,45835,45990,46130,46287,46429,46572,46684,46853,47015,47178,47326,47491,47641,47792,47912,48081,48235,48390,48514,48671,48797,48924,48988,49177,49363,49550,49730,49919,50101,50284,50452,50645,50831,51018,51190,51379,51553,51728,51872,52073,52267,52462,52642,52839,53021,53204,53356,53557,53743,53930,54086,54275,54433,54592,54688,54905,55115,55326,55522,55735,55933,56132,56300,56517,56719,56922,57094,57299,57473,57648,57760,57985,58195,58406,58586,58799,58981,59164,59284,59501,59687,59874,59998,60187,60313,60440,60440,60695,60949,61204,61456,61713,61967,62222,62470,62731,62989,63248,63500,63761,64015,64270,64510,64779,65045,65312,65572,65841,66103,66366,66614,66887,67153,67420,67672,67941,68195,68450,68674,68959,69241,69524,69800,70085,70363,70642,70906,71195,71477,71760,72028,72313,72583,72854,73094,73391,73681,73972,74248,74541,74819,75098,75346,75643,75925,76208,76460,76745,76999,77254,77446,77763,78077,78392,78700,79017,79327,79638,79934,80255,80569,80884,81184,81501,81803,82106,82378,82707,83029,83352,83660,83985,84295,84606,84886,85215,85529,85844,86128,86445,86731,87018,87242,87587,87925,88264,88588,88929,89255,89582,89878,90223,90553,90884,91184,91517,91819,92122,92362,92715,93053,93392,93700,94041,94351,94662,94910,95255,95569,95884,96136,96453,96707,96962,97090,97471,97849,98228,98600,98981,99355,99730,100090,100475,100853,101232,101596,101977,102343,102710,103046,103439,103825,104212,104584,104973,105347,105722,106066,106459,106837,107216,107564,107945,108295,108646,108934,109343,109745,110148,110536,110941,111331,111722,112082,112491,112885,113280,113644,114041,114407,114774,115078,115495,115897,116300,116672,117077,117451,117826,118138,118547,118925,119304,119620,120001,120319,120638,120830,121271,121705,122140,122560,122997,123419,123842,124234,124675,125101,125528,125924,126353,126751,127150,127486,127935,128369,128804,129208,129645,130051,130458,130802,131243,131653,132064,132412,132825,133175,133526,133750,134215,134665,135116,135536,135989,136411,136834,137194,137651,138077,138504,138868,139297,139663,140030,140270,140735,141169,141604,141976,142413,142787,143162,143410,143851,144229,144608,144860,145241,145495,145750,145750,145750,145750,145751,145751,145754,145756,145759,145759,145766,145772,145779,145783,145792,145798,145805,145805,145820,145834,145849,145861,145878,145892,145907,145915,145936,145954,145973,145985,146006,146020,146035,146035,146066,146096,146127,146155,146188,146218,146249,146273,146310,146344,146379,146407,146444,146474,146505,146521,146566,146608,146651,146687,146732,146770,146809,146833,146882,146924,146967,146995,147040,147070,147101,147101,147164,147226,147289,147349,147414,147476,147539,147595,147664,147730,147797,147857,147926,147988,148051,148099,148176,148250,148325,148393,148470,148540,148611,148667,148748,148822,148897,148957,149034,149096,149159,149191,149284,149374,149465,149549,149642,149728,149815,149887,149984,150074,150165,150241,150334,150412,150491,150539,150644,150742,150841,150925,151026,151112,151199,151255,151360,151450,151541,151601,151694,151756,151819,151819,151946,152072,152199,152323,152452,152578,152705,152825,152958,153088,153219,153343,153476,153602,153729,153841,153982,154120,154259,154391,154532,154666,154801,154921,155066,155204,155343,155467,155608,155734,155861,155957,156114,156268,156423,156571,156728,156878,157029,157165,157326,157480,157635,157775,157932,158074,158217,158329,158498,158660,158823,158971,159136,159286,159437,159557,159726,159880,160035,160159,160316,160442,160569,160633,160822,161008,161195,161375,161564,161746,161929,162097,162290,162476,162663,162835,163024,163198,163373,163517,163718,163912,164107,164287,164484,164666,164849,165001,165202,165388,165575,165731,165920,166078,166237,166333,166550,166760,166971,167167,167380,167578,167777,167945,168162,168364,168567,168739,168944,169118,169293,169405,169630,169840,170051,170231,170444,170626,170809,170929,171146,171332,171519,171643,171832,171958,172085,172085,172340,172594,172849,173101,173358,173612,173867,174115,174376,174634,174893,175145,175406,175660,175915,176155,176424,176690,176957,177217,177486,177748,178011,178259,178532,178798,179065,179317,179586,179840,180095,180319,180604,180886,181169,181445,181730,182008,182287,182551,182840,183122,183405,183673,183958,184228,184499,184739,185036,185326,185617,185893,186186,186464,186743,186991,187288,187570,187853,188105,188390,188644,188899,189091,189408,189722,190037,190345,190662,190972,191283,191579,191900,192214,192529,192829,193146,193448,193751,194023,194352,194674,194997,195305,195630,195940,196251,196531,196860,197174,197489,197773,198090,198376,198663,198887,199232,199570,199909,200233,200574,200900,201227,201523,201868,202198,202529,202829,203162,203464,203767,204007,204360,204698,205037,205345,205686,205996,206307,206555,206900,207214,207529,207781,208098,208352,208607,208735,209116,209494,209873,210245,210626,211000,211375,211735,212120,212498,212877,213241,213622,213988,214355,214691,215084,215470,215857,216229,216618,216992,217367,217711,218104,218482,218861,219209,219590,219940,220291,220579,220988,221390,221793,222181,222586,222976,223367,223727,224136,224530,224925,225289,225686,226052,226419,226723,227140,227542,227945,228317,228722,229096,229471,229783,230192,230570,230949,231265,231646,231964,232283,232475,232916,233350,233785,234205,234642,235064,235487,235879,236320,236746,237173,237569,237998,238396,238795,239131,239580,240014,240449,240853,241290,241696,242103,242447,242888,243298,243709,244057,244470,244820,245171,245395,245860,246310,246761,247181,247634,248056,248479,248839,249296,249722,250149,250513,250942,251308,251675,251915,252380,252814,253249,253621,254058,254432,254807,255055,255496,255874,256253,256505,256886,257140,257395,257395,257906,258416,258927,259435,259948,260458,260969,261473,261990,262504,263019,263527,264044,264554,265065,265561,266086,266608,267131,267647,268172,268690,269209,269713,270242,270764,271287,271795,272320,272830,273341,273821,274362,274900,275439,275971,276512,277046,277581,278101,278646,279184,279723,280247,280788,281314,281841,282337,282890,283436,283983,284515,285064,285598,286133,286637,287190,287728,288267,288775,289316,289826,290337,290785,291358,291928,292499,293063,293636,294202,294769,295321,295898,296468,297039,297595,298168,298726,299285,299813,300398,300976,301555,302119,302700,303266,303833,304369,304954,305524,306095,306635,307208,307750,308293,308773,309374,309968,310563,311143,311740,312322,312905,313457,314058,314644,315231,315787,316376,316934,317493,317989,318598,319192,319787,320351,320948,321514,322081,322585,323186,323756,324327,324835,325408,325918,326429,326813,327450,328084,328719,329347,329984,330614,331245,331861,332502,333136,333771,334391,335028,335650,336273,336865,337514,338156,338799,339427,340072,340702,341333,341933,342582,343216,343851,344455,345092,345698,346305,346849,347514,348172,348831,349475,350136,350782,351429,352045,352710,353360,354011,354631,355284,355906,356529,357089,357762,358420,359079,359707,360368,360998,361629,362197,362862,363496,364131,364703,365340,365914,366489,366937,367634,368324,369015,369691,370384,371062,371741,372389,373086,373768,374451,375103,375788,376442,377097,377689,378394,379084,379775,380435,381128,381790,382453,383053,383750,384416,385083,385687,386356,386962,387569,388049,388770,389476,390183,390859,391568,392246,392925,393541,394254,394936,395619,396239,396924,397546,398169,398665,399386,400076,400767,401395,402088,402718,403349,403853,404550,405184,405819,406327,406964,407474,407985,408241,409006,409768,410531,411287,412052,412810,413569,414313,415082,415844,416607,417355,418120,418870,419621,420341,421118,421888,422659,423415,424188,424946,425705,426433,427210,427972,428735,429467,430232,430966,431701,432373,433166,433952,434739,435511,436300,437074,437849,438593,439386,440164,440943,441691,442472,443222,443973,444661,445462,446248,447035,447791,448580,449338,450097,450793,451586,452348,453111,453811,454576,455278,455981,456557,457382,458200,459019,459823,460644,461450,462257,463033,463858,464668,465479,466259,467072,467854,468637,469357,470190,471008,471827,472615,473436,474226,475017,475745,476570,477364,478159,478891,479688,480422,481157,481765,482614,483448,484283,485087,485924,486730,487537,488281,489122,489932,490743,491491,492304,493054,493805,494429,495278,496096,496915,497671,498492,499250,500009,500641,501466,502228,502991,503627,504392,505030,505669,506053,506942,507824,508707,509575,510460,511330,512201,513041,513930,514804,515679,516523,517400,518246,519093,519877,520774,521656,522539,523391,524276,525130,525985,526777,527666,528524,529383,530179,531040,531838,532637,533309,534222,535120,536019,536887,537788,538658,539529,540337,541242,542116,542991,543803,544680,545494,546309,546997,547910,548792,549675,550495,551380,552202,553025,553721,554610,555436,556263,556963,557792,558494,559197,559645,560590,561520,562451,563351,564284,565186,566089,566929,567866,568772,569679,570523,571432,572278,573125,573845,574790,575704,576619,577471,578388,579242,580097,580825,581746,582604,583463,584195,585056,585790,586525,587005,587966,588896,589827,590695,591628,592498,593369,594113,595050,595924,596799,597547,598424,599174,599925,600421,601366,602248,603131,603887,604772,605530,606289,606793,607682,608444,609207,609715,610480,610990,611501,611501,611501,611501,611502,611502,611505,611507,611510,611510,611517,611523,611530,611534,611543,611549,611556,611556,611571,611585,611600,611612,611629,611643,611658,611666,611687,611705,611724,611736,611757,611771,611786,611786,611817,611847,611878,611906,611939,611969,612000,612024,612061,612095,612130,612158,612195,612225,612256,612272,612317,612359,612402,612438,612483,612521,612560,612584,612633,612675,612718,612746,612791,612821,612852,612852,612915,612977,613040,613100,613165,613227,613290,613346,613415,613481,613548,613608,613677,613739,613802,613850,613927,614001,614076,614144,614221,614291,614362,614418,614499,614573,614648,614708,614785,614847,614910,614942,615035,615125,615216,615300,615393,615479,615566,615638,615735,615825,615916,615992,616085,616163,616242,616290,616395,616493,616592,616676,616777,616863,616950,617006,617111,617201,617292,617352,617445,617507,617570,617570,617697,617823,617950,618074,618203,618329,618456,618576,618709,618839,618970,619094,619227,619353,619480,619592,619733,619871,620010,620142,620283,620417,620552,620672,620817,620955,621094,621218,621359,621485,621612,621708,621865,622019,622174,622322,622479,622629,622780,622916,623077,623231,623386,623526,623683,623825,623968,624080,624249,624411,624574,624722,624887,625037,625188,625308,625477,625631,625786,625910,626067,626193,626320,626384,626573,626759,626946,627126,627315,627497,627680,627848,628041,628227,628414,628586,628775,628949,629124,629268,629469,629663,629858,630038,630235,630417,630600,630752,630953,631139,631326,631482,631671,631829,631988,632084,632301,632511,632722,632918,633131,633329,633528,633696,633913,634115,634318,634490,634695,634869,635044,635156,635381,635591,635802,635982,636195,636377,636560,636680,636897,637083,637270,637394,637583,637709,637836,637836,638091,638345,638600,638852,639109,639363,639618,639866,640127,640385,640644,640896,641157,641411,641666,641906,642175,642441,642708,642968,643237,643499,643762,644010,644283,644549,644816,645068,645337,645591,645846,646070,646355,646637,646920,647196,647481,647759,648038,648302,648591,648873,649156,649424,649709,649979,650250,650490,650787,651077,651368,651644,651937,652215,652494,652742,653039,653321,653604,653856,654141,654395,654650,654842,655159,655473,655788,656096,656413,656723,657034,657330,657651,657965,658280,658580,658897,659199,659502,659774,660103,660425,660748,661056,661381,661691,662002,662282,662611,662925,663240,663524,663841,664127,664414,664638,664983,665321,665660,665984,666325,666651,666978,667274,667619,667949,668280,668580,668913,669215,669518,669758,670111,670449,670788,671096,671437,671747,672058,672306,672651,672965,673280,673532,673849,674103,674358,674486,674867,675245,675624,675996,676377,676751,677126,677486,677871,678249,678628,678992,679373,679739,680106,680442,680835,681221,681608,681980,682369,682743,683118,683462,683855,684233,684612,684960,685341,685691,686042,686330,686739,687141,687544,687932,688337,688727,689118,689478,689887,690281,690676,691040,691437,691803,692170,692474,692891,693293,693696,694068,694473,694847,695222,695534,695943,696321,696700,697016,697397,697715,698034,698226,698667,699101,699536,699956,700393}; 10 | cout << arr[n]; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Code Forces/938-A/938A Word Correction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int correct(string s) 5 | { 6 | int l=s.length(); 7 | if(l==1) 8 | return -1; 9 | for(int i=0;i> l; 29 | string s; 30 | cin >> s; 31 | int x; 32 | while(correct(s)!=-1) 33 | { 34 | x=correct(s); 35 | s.erase(s.begin() + x); 36 | } 37 | cout << s; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Code Forces/938-B/938B Run For Your Prize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int32_t main() 5 | { 6 | int n; 7 | cin >> n; 8 | int arr[n]; 9 | for(int i=0;i> arr[i]; 12 | } 13 | 14 | int mid=1000000/2; 15 | 16 | vector v1,v2; 17 | 18 | for(int i=0;i 2 | using namespace std; 3 | int32_t main() 4 | { 5 | int n; 6 | cin >> n; 7 | int arr[n]; 8 | for(int i=0;i> arr[i]; 11 | } 12 | 13 | for(int i=0;i 2 | using namespace std; 3 | int32_t main() 4 | { 5 | int n,k; 6 | cin >> n >> k; 7 | int x; 8 | int arr[n]; 9 | int ansindex=1; 10 | int ans=0; 11 | int compare=0; 12 | 13 | for(int i=0;i> x; 16 | 17 | if((x*((int)n/x))>compare) 18 | { 19 | compare=x*((int)n/x); 20 | ans=n/x; 21 | ansindex=i+1; 22 | } 23 | } 24 | 25 | cout << ansindex << " " << ans; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Code Forces/96-A/96A Football.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string s; 6 | cin >> s; 7 | int flag=0; 8 | int l=s.length(); 9 | int countz=0,counto=0; 10 | int max; 11 | for(int i=0;i 0: 78 | # bcount -= 1 79 | # continue 80 | # else: 81 | # fin.append(s[i]) 82 | # return "".join(fin) 83 | 84 | # return bsp(S) == bsp(T) 85 | 86 | # Solution #2 87 | 88 | # class Solution(object): 89 | # def backspaceCompare(self, S, T): 90 | # """ 91 | # :type S: str 92 | # :type T: str 93 | # :rtype: bool 94 | # """ 95 | # i = len(S)-1 96 | # j = len(T)-1 97 | # bs_s = 0 98 | # bs_t = 0 99 | # while True: 100 | # while i >= 0 and (bs_s or S[i] == '#'): 101 | # if S[i] == '#': 102 | # bs_s +=1 103 | # else: 104 | # bs_s -= 1 105 | # i -= 1 106 | # while j >= 0 and (bs_t or T[j] == '#'): 107 | # if T[j] == '#': 108 | # bs_t += 1 109 | # else: 110 | # bs_t -= 1 111 | # j -= 1 112 | # if not (i >= 0 and j >=0 and S[i] == T[j]): 113 | # return i == j == -1 114 | # i -= 1 115 | # j -= 1 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /LeetCode/Best-Time-to-Buy-and-Sell-Stock-II.py: -------------------------------------------------------------------------------- 1 | # Best Time to Buy and Sell Stock II 2 | 3 | # Say you have an array for which the ith element is the price of a given stock on day i. 4 | 5 | # Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). 6 | 7 | # Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). 8 | 9 | # Example 1: 10 | 11 | # Input: [7,1,5,3,6,4] 12 | # Output: 7 13 | # Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4. 14 | # Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3. 15 | # Example 2: 16 | 17 | # Input: [1,2,3,4,5] 18 | # Output: 4 19 | # Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4. 20 | # Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are 21 | # engaging multiple transactions at the same time. You must sell before buying again. 22 | # Example 3: 23 | 24 | # Input: [7,6,4,3,1] 25 | # Output: 0 26 | # Explanation: In this case, no transaction is done, i.e. max profit = 0. 27 | 28 | class Solution(object): 29 | def maxProfit(self, prices): 30 | """ 31 | :type prices: List[int] 32 | :rtype: int 33 | """ 34 | if prices == None or len(prices) == 0: 35 | return 0 36 | 37 | profit = 0 38 | for i in range(0,len(prices)-1): 39 | if(prices[i+1]>prices[i]): 40 | profit+=prices[i+1]-prices[i] 41 | 42 | return profit 43 | 44 | # My solution is a very straightforward and efficient solution, it is better than 45 | # 96% of the solutions. 46 | 47 | # More optimal Solutions 48 | # Solution 1 49 | # class Solution(object): 50 | # def maxProfit(self, prices): 51 | # """ 52 | # :type prices: List[int] 53 | # :rtype: int 54 | # """ 55 | # length = len(prices) 56 | # if length < 2: return 0 57 | # max_profit = 0 58 | # for i in range(1, length): 59 | # if prices[i - 1] < prices[i]: 60 | # max_profit += prices[i] - prices[i - 1] 61 | # return max_profit 62 | 63 | # Solution 2 64 | # class Solution(object): 65 | # def maxProfit(self, prices): 66 | # """ 67 | # :type prices: List[int] 68 | # :rtype: int 69 | # """ 70 | # profit=0 71 | 72 | # for i in range(1,len(prices)): 73 | # if(prices[i]>prices[i-1]): 74 | # profit+=prices[i]-prices[i-1] 75 | # return profit 76 | -------------------------------------------------------------------------------- /LeetCode/Contiguous-Array.py: -------------------------------------------------------------------------------- 1 | # Contiguous Array 2 | 3 | # Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. 4 | 5 | # Example 1: 6 | # Input: [0,1] 7 | # Output: 2 8 | # Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1. 9 | # Example 2: 10 | # Input: [0,1,0] 11 | # Output: 2 12 | # Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1. 13 | # Note: The length of the given binary array will not exceed 50,000` 14 | 15 | class Solution(object): 16 | def findMaxLength(self, nums): 17 | """ 18 | :type nums: List[int] 19 | :rtype: int 20 | """ 21 | count = 0 22 | max_length=0 23 | table = {0: 0} 24 | for index, num in enumerate(nums, 1): 25 | if num == 0: 26 | count -= 1 27 | else: 28 | count += 1 29 | 30 | if count in table: 31 | max_length = max(max_length, index - table[count]) 32 | else: 33 | table[count] = index 34 | 35 | return max_length 36 | 37 | # Better than 90%. I think this is good enough. Yes. -------------------------------------------------------------------------------- /LeetCode/Counting-Elements.py: -------------------------------------------------------------------------------- 1 | # Counting Elements 2 | 3 | # Given an integer array arr, count element x such that x + 1 is also in arr. 4 | 5 | # If there're duplicates in arr, count them seperately. 6 | 7 | 8 | 9 | # Example 1: 10 | 11 | # Input: arr = [1,2,3] 12 | # Output: 2 13 | # Explanation: 1 and 2 are counted cause 2 and 3 are in arr. 14 | # Example 2: 15 | 16 | # Input: arr = [1,1,3,3,5,5,7,7] 17 | # Output: 0 18 | # Explanation: No numbers are counted, cause there's no 2, 4, 6, or 8 in arr. 19 | # Example 3: 20 | 21 | # Input: arr = [1,3,2,3,5,0] 22 | # Output: 3 23 | # Explanation: 0, 1 and 2 are counted cause 1, 2 and 3 are in arr. 24 | # Example 4: 25 | 26 | # Input: arr = [1,1,2,2] 27 | # Output: 2 28 | # Explanation: Two 1s are counted cause 2 is in arr. 29 | 30 | 31 | # Constraints: 32 | 33 | # 1 <= arr.length <= 1000 34 | # 0 <= arr[i] <= 1000 35 | # Hide Hint #1 36 | # Use hashset to store all elements. 37 | # Hide Hint #2 38 | # Loop again to count all valid elements. 39 | 40 | class Solution(object): 41 | def countElements(self, arr): 42 | """ 43 | :type arr: List[int] 44 | :rtype: int 45 | """ 46 | ls= set(arr) 47 | count = 0 48 | for x in arr: 49 | if(x+1 in ls): 50 | count+=1 51 | return count 52 | 53 | # More Optimal Solutions do not exist for this question. 54 | # They have locked the platform. -------------------------------------------------------------------------------- /LeetCode/Diameter-of-Binary-Tree.py: -------------------------------------------------------------------------------- 1 | # Diameter of Binary Tree 2 | # Given a binary tree, you need to compute the length of the diameter of the 3 | # tree. The diameter of a binary tree is the length of the longest path between 4 | # any two nodes in a tree. This path may or may not pass through the root. 5 | 6 | # Example: 7 | # Given a binary tree 8 | # 1 9 | # / \ 10 | # 2 3 11 | # / \ 12 | # 4 5 13 | # Return 3, which is the length of the path [4,2,1,3] or [5,2,1,3]. 14 | 15 | # Note: The length of path between two nodes is represented by the number of edges between them. 16 | 17 | # Definition for a binary tree node. 18 | # class TreeNode(object): 19 | # def __init__(self, x): 20 | # self.val = x 21 | # self.left = None 22 | # self.right = None 23 | 24 | class Solution(object): 25 | def diameterOfBinaryTree(self, root): 26 | """ 27 | :type root: TreeNode 28 | :rtype: int 29 | """ 30 | self.ans = 0 31 | def depth(root): 32 | if not root: 33 | return 0 34 | left = depth(root.left) 35 | right = depth(root.right) 36 | self.ans = max(self.ans, left + right) 37 | return max(left, right) + 1 38 | 39 | depth(root) 40 | return self.ans 41 | 42 | # This surprizingly was the most optimal solution. I beat 99% of all submissions. 43 | 44 | 45 | -------------------------------------------------------------------------------- /LeetCode/Group-Anagrams.py: -------------------------------------------------------------------------------- 1 | # Group Anagrams 2 | 3 | # Given an array of strings, group anagrams together. 4 | 5 | # Example: 6 | 7 | # Input: ["eat", "tea", "tan", "ate", "nat", "bat"], 8 | # Output: 9 | # [ 10 | # ["ate","eat","tea"], 11 | # ["nat","tan"], 12 | # ["bat"] 13 | # ] 14 | # Note: 15 | 16 | # All inputs will be in lowercase. 17 | # The order of your output does not matter. 18 | 19 | class Solution(object): 20 | def groupAnagrams(self, strs): 21 | """ 22 | :type strs: List[str] 23 | :rtype: List[List[str]] 24 | """ 25 | output = {} 26 | for i in strs: 27 | word = "".join(sorted(i)) 28 | if word in output: 29 | output[word].append(i) 30 | else: 31 | output[word] = [i] 32 | return list(output.values()) 33 | 34 | # More optimal solutions 35 | 36 | #Solution 1 37 | 38 | # class Solution(object): 39 | # def groupAnagrams(self, strs): 40 | # """ 41 | # :type strs: List[str] 42 | # :rtype: List[List[str]] 43 | # """ 44 | # d = collections.defaultdict(list) 45 | 46 | # for x in strs: 47 | # xl = ''.join(sorted(x)) 48 | # d[xl].append(x) 49 | 50 | # return d.values() 51 | 52 | 53 | #Solution 2 54 | 55 | # class Solution(object): 56 | # def groupAnagrams(self, strs): 57 | # """ 58 | # :type strs: List[str] 59 | # :rtype: List[List[str]] 60 | # """ 61 | # repo = {} 62 | # res = [] 63 | # for word in strs: 64 | # temp = ''.join(sorted(word)) 65 | # if temp in repo: 66 | # res[repo[temp]].append(word) 67 | # else: 68 | # current_len = len(res) 69 | # res.append([word]) 70 | # repo[temp] = current_len 71 | # return res 72 | 73 | #Solution 3 74 | 75 | # class Solution(object): 76 | # def groupAnagrams(self, strs): 77 | # """ 78 | # :type strs: List[str] 79 | # :rtype: List[List[str]] 80 | 81 | # """ 82 | # answer=collections.defaultdict(list) 83 | 84 | # for s in strs: 85 | # answer[tuple(sorted(s))].append(s) 86 | # return answer.values() 87 | 88 | #Solution 4 89 | # class Solution(object): 90 | # def groupAnagrams(self, strs): 91 | # ans = collections.defaultdict(list) 92 | # for i in strs: 93 | # ans[tuple(sorted(i))].append(i) 94 | # return ans.values() -------------------------------------------------------------------------------- /LeetCode/Happy-Number.py: -------------------------------------------------------------------------------- 1 | # Happy Number 2 | 3 | # Write an algorithm to determine if a number is "happy". 4 | 5 | # A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers. 6 | 7 | # Example: 8 | 9 | # Input: 19 10 | # Output: true 11 | # Explanation: 12 | # 12 + 92 = 82 13 | # 82 + 22 = 68 14 | # 62 + 82 = 100 15 | # 12 + 02 + 02 = 1 16 | 17 | class Solution(object): 18 | def sums(self, n): 19 | nextnum = 0 20 | while n != 0: 21 | nextnum += (n % 10) **2 22 | n /= 10 23 | return nextnum 24 | 25 | def isHappy(self, n): 26 | """ 27 | :type n: int 28 | :rtype: bool 29 | """ 30 | keep = set() 31 | while not n in keep: 32 | if n == 1: 33 | return True 34 | keep.add(n) 35 | n = self.sums(n) 36 | return False 37 | 38 | 39 | #More optimal solutions 40 | #Solution #1 41 | # class Solution(object): 42 | # def isHappy(self, n): 43 | # """ 44 | # :type n: int 45 | # :rtype: bool 46 | # """ 47 | # dic = {} 48 | # while n!=1: 49 | # m = n 50 | # temp = 0 51 | # while m: 52 | # temp += (m%10)**2 53 | # m = m/10 54 | # if temp in dic: return False 55 | # else: dic[temp] = 1 56 | # n = temp 57 | # return True 58 | 59 | #Solution #2 60 | # class Solution(object): 61 | 62 | # def isHappy(self, n): 63 | # """ 64 | # :type n: int 65 | # :rtype: bool 66 | # """ 67 | # def helper(n): 68 | # total = 0 69 | # while n > 0: 70 | # reminder = n % 10 71 | # total += reminder ** 2 72 | # n = n // 10 73 | # return int(total) 74 | # seen = set() 75 | # while n != 1: 76 | # if n in seen: 77 | # return False 78 | # seen.add(n) 79 | # n = helper(n) 80 | # return True -------------------------------------------------------------------------------- /LeetCode/Last-Stone-Weight.py: -------------------------------------------------------------------------------- 1 | # Last Stone Weight 2 | # We have a collection of stones, each stone has a positive integer weight. 3 | 4 | # Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is: 5 | 6 | # If x == y, both stones are totally destroyed; 7 | # If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x. 8 | # At the end, there is at most 1 stone left. Return the weight of this stone (or 0 if there are no stones left.) 9 | 10 | 11 | 12 | # Example 1: 13 | 14 | # Input: [2,7,4,1,8,1] 15 | # Output: 1 16 | # Explanation: 17 | # We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then, 18 | # we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then, 19 | # we combine 2 and 1 to get 1 so the array converts to [1,1,1] then, 20 | # we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone. 21 | 22 | 23 | # Note: 24 | 25 | # 1 <= stones.length <= 30 26 | # 1 <= stones[i] <= 1000 27 | # Hide Hint #1 28 | # Simulate the process. We can do it with a heap, or by sorting some list of stones every time we take a turn. 29 | 30 | class Solution(object): 31 | def lastStoneWeight(self, stones): 32 | """ 33 | :type stones: List[int] 34 | :rtype: int 35 | """ 36 | for i in range(len(stones) - 1): 37 | stones.sort() 38 | stones.append(stones.pop() - stones.pop()) 39 | return stones[0] 40 | 41 | # More optimal Solutions 42 | # Solutions #1 43 | # class Solution(object): 44 | # def lastStoneWeight(self, stones): 45 | # """ 46 | # :type stones: List[int] 47 | # :rtype: int 48 | # """ 49 | # h = [-x for x in stones] 50 | # heapq.heapify(h) 51 | 52 | # while len(h) >1 and h[0] != 0: 53 | # heapq.heappush(h, heapq.heappop(h)- heapq.heappop(h)) 54 | 55 | # return -h[0] 56 | 57 | #Solution #2 58 | # import heapq 59 | 60 | # class Solution(object): 61 | # def lastStoneWeight(self, stones): 62 | # """ 63 | # :type stones: List[int] 64 | # :rtype: int 65 | # """ 66 | # stones = [-x for x in stones] 67 | # heapq.heapify(stones) # so that it is a max-heap 68 | 69 | # while len(stones) >= 2: # revisit this condition 70 | 71 | # itemY = heapq.heappop(stones) 72 | # itemX = heapq.heappop(stones) 73 | 74 | # if itemX != itemY: 75 | # heapq.heappush(stones, itemY-itemX) 76 | 77 | # ans = None 78 | # try: 79 | # return -heapq.heappop(stones) 80 | # except IndexError: 81 | # return 0 82 | 83 | #Solution #3 84 | # class Solution(object): 85 | # def lastStoneWeight(self, stones): 86 | # """ 87 | # :type stones: List[int] 88 | # :rtype: int 89 | # """ 90 | # while len(stones)>1: 91 | # a = max(stones) 92 | # stones.remove(a) 93 | # b = max(stones) 94 | # stones.remove(b) 95 | # if (a!=b): 96 | # stones.append(a-b) 97 | # return stones[0] if stones else 0 98 | 99 | #Solution #4 100 | # class Solution(object): 101 | # def lastStoneWeight(self, stones): 102 | # """ 103 | # :type stones: List[int] 104 | # :rtype: int 105 | # """ 106 | # stones.sort() 107 | # stones = [0]+stones 108 | # while len(stones)>1: 109 | # if stones[-1]==stones[-2]: 110 | # stones.pop() 111 | # stones.pop() 112 | # else: 113 | # stones[-1] -=stones[-2] 114 | # stones.pop(-2) 115 | # stones.sort() 116 | # return stones[0] 117 | 118 | #Solution #5 119 | # class Solution(object): 120 | 121 | # def smash(self, s1, s2): 122 | # return abs(s1 - s2) 123 | 124 | # def lastStoneWeight(self, stones): 125 | # """ 126 | # :type stones: List[int] 127 | # :rtype: int 128 | # """ 129 | 130 | # while len(stones) > 1: 131 | # s1 = max(stones) 132 | # is1 = stones.index(s1) 133 | # stones.pop(is1) 134 | # s2 = max(stones) 135 | # is2 = stones.index(s2) 136 | # stones.pop(is2) 137 | # stones.append(abs(s1 - s2)) 138 | 139 | # return stones[0] 140 | 141 | -------------------------------------------------------------------------------- /LeetCode/Maximum-Subarray.py: -------------------------------------------------------------------------------- 1 | #Maximum Subarray 2 | 3 | # Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. 4 | 5 | # Example: 6 | 7 | # Input: [-2,1,-3,4,-1,2,1,-5,4], 8 | # Output: 6 9 | # Explanation: [4,-1,2,1] has the largest sum = 6. 10 | # Follow up: 11 | 12 | # If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle 13 | 14 | #Kadane's Algorithm 15 | 16 | class Solution(object): 17 | def maxSubArray(self, nums): 18 | """ 19 | :type nums: List[int] 20 | :rtype: int 21 | """ 22 | max_s, cur_s = -float("inf"), 0 23 | for i in range(len(nums)): 24 | max_s = max(max_s, cur_s+nums[i]) 25 | cur_s = max(cur_s+nums[i], 0) 26 | return max_s 27 | 28 | #More optimal solutions 29 | #Solution #1 30 | # import sys 31 | 32 | # class Solution(object): 33 | # def maxSubArray(self, nums): 34 | # total, maxsize = 0, -2147483648 35 | 36 | # for val in nums: 37 | # total += val 38 | # if total > maxsize: 39 | # maxsize = total 40 | 41 | # if total < 0: 42 | # total = 0 43 | 44 | # return maxsize 45 | 46 | #Solution #2 47 | # class Solution(object): 48 | # def maxSubArray(self, nums): 49 | # """ 50 | # :type nums: List[int] 51 | # :rtype: int 52 | # """ 53 | # maxSum = 0 54 | # runningSum = 0 55 | # for elt in nums: 56 | # runningSum+=elt 57 | # if runningSum>=maxSum: 58 | # maxSum=runningSum 59 | # if runningSum<0: 60 | # runningSum=0 61 | # if maxSum==0 and runningSum==0: 62 | # return max(nums) 63 | # return maxSum 64 | 65 | #Solution #3 66 | # class Solution(object): 67 | # def maxSubArray(self, nums): 68 | # """ 69 | # :type nums: List[int] 70 | # :rtype: int 71 | # """ 72 | # ### kadane's algorithm, check for positive contiguous segments 73 | # if (len(nums) == 0): return 0 74 | # if (len(nums) == 1): return nums[0] 75 | # for i in range(1, len(nums)): 76 | # nums[i] = max(nums[i], nums[i] + nums[i-1]) 77 | # return max(nums) -------------------------------------------------------------------------------- /LeetCode/Middle-of-the-Linked-List.py: -------------------------------------------------------------------------------- 1 | # Middle of the Linked List 2 | 3 | # Given a non-empty, singly linked list with head node head, return a middle node of linked list. 4 | 5 | # If there are two middle nodes, return the second middle node. 6 | 7 | # Example 1: 8 | 9 | # Input: [1,2,3,4,5] 10 | # Output: Node 3 from this list (Serialization: [3,4,5]) 11 | # The returned node has value 3. (The judge's serialization of this node is [3,4,5]). 12 | # Note that we returned a ListNode object ans, such that: 13 | # ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL. 14 | # Example 2: 15 | 16 | # Input: [1,2,3,4,5,6] 17 | # Output: Node 4 from this list (Serialization: [4,5,6]) 18 | # Since the list has two middle nodes with values 3 and 4, we return the second one. 19 | 20 | # Note: 21 | 22 | # The number of nodes in the given list will be between 1 and 100. 23 | 24 | # Definition for singly-linked list. 25 | # class ListNode(object): 26 | # def __init__(self, x): 27 | # self.val = x 28 | # self.next = None 29 | 30 | class Solution(object): 31 | def middleNode(self, head): 32 | """ 33 | :type head: ListNode 34 | :rtype: ListNode 35 | """ 36 | fast = slow = head 37 | while fast and fast.next: 38 | fast = fast.next.next 39 | slow = slow.next 40 | return slow 41 | 42 | #No other more optimal methods are shared. -------------------------------------------------------------------------------- /LeetCode/Min-Stackpy.py: -------------------------------------------------------------------------------- 1 | # Min Stack 2 | 3 | # Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. 4 | 5 | # push(x) -- Push element x onto stack. 6 | # pop() -- Removes the element on top of the stack. 7 | # top() -- Get the top element. 8 | # getMin() -- Retrieve the minimum element in the stack. 9 | 10 | 11 | # Example: 12 | 13 | # MinStack minStack = new MinStack(); 14 | # minStack.push(-2); 15 | # minStack.push(0); 16 | # minStack.push(-3); 17 | # minStack.getMin(); --> Returns -3. 18 | # minStack.pop(); 19 | # minStack.top(); --> Returns 0. 20 | # minStack.getMin(); --> Returns -2. 21 | 22 | 23 | # Hide Hint #1 24 | # Consider each node in the stack having a minimum value. 25 | 26 | class MinStack: 27 | 28 | def __init__(self): 29 | self.s = [] 30 | 31 | def push(self, x): 32 | cur_min = self.getMin() 33 | if cur_min == None or x < cur_min: 34 | cur_min = x 35 | self.s.append((x,cur_min)) 36 | 37 | 38 | def pop(self): 39 | self.s.pop() 40 | 41 | def top(self): 42 | if len(self.s) == 0: 43 | return None 44 | return self.s[-1][0] 45 | 46 | def getMin(self): 47 | if len(self.s) == 0: 48 | return None 49 | return self.s[-1][1] 50 | 51 | 52 | 53 | # Your MinStack object will be instantiated and called as such: 54 | # obj = MinStack() 55 | # obj.push(x) 56 | # obj.pop() 57 | # param_3 = obj.top() 58 | # param_4 = obj.getMin() 59 | 60 | #More Optimal Solutions 61 | 62 | # Solution 1 63 | 64 | # class MinStack(object): 65 | 66 | # def __init__(self): 67 | # self.stack = [] 68 | # self.mins = [] 69 | # def push(self, x): 70 | # """ 71 | # :type x: int 72 | # :rtype: None 73 | # """ 74 | # self.stack.append(x) 75 | # if not self.mins: 76 | # self.mins.append(x) 77 | # else: 78 | # if x <= self.mins[-1]: 79 | # self.mins.append(x) 80 | # def pop(self): 81 | # """ 82 | # :rtype: None 83 | # """ 84 | # temp = self.stack.pop() 85 | # if temp == self.mins[-1]: 86 | # self.mins.pop() 87 | 88 | 89 | # def top(self): 90 | # """ 91 | # :rtype: int 92 | # """ 93 | # return self.stack[-1] 94 | 95 | 96 | # def getMin(self): 97 | # """ 98 | # :rtype: int 99 | # """ 100 | # return self.mins[-1] 101 | 102 | 103 | -------------------------------------------------------------------------------- /LeetCode/Move-Zeroes.py: -------------------------------------------------------------------------------- 1 | # Move Zeroes 2 | 3 | # Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. 4 | 5 | # Example: 6 | 7 | # Input: [0,1,0,3,12] 8 | # Output: [1,3,12,0,0] 9 | # Note: 10 | 11 | # You must do this in-place without making a copy of the array. 12 | # Minimize the total number of operations. 13 | 14 | class Solution(object): 15 | def moveZeroes(self, nums): 16 | """ 17 | :type nums: List[int] 18 | :rtype: None Do not return anything, modify nums in-place instead. 19 | """ 20 | for i in range(len(nums)): 21 | if nums[i]==0: 22 | nums.append(nums[i]) 23 | nums.remove(nums[i]) 24 | return nums 25 | 26 | # This is my approach. It took me about 16 seconds to come up with this solution, 27 | # The issue is, it is inefficient. 28 | 29 | # My second attempt after realizing that the previous setup is inefficient. 30 | # Took me about 5 minutes on Python Tutor. 31 | # def moveZeroes(self, nums): 32 | # """ 33 | # :type nums: List[int] 34 | # :rtype: None Do not return anything, modify nums in-place instead. 35 | # """ 36 | # tail = 0 37 | # for i in range(0, len(nums)): 38 | # if nums[i] !=0: 39 | # nums[tail] = nums[i] 40 | # tail+=1 41 | # 42 | # for i in range(tail, len(nums), 1): 43 | # nums[i]=0 44 | 45 | #More optimal Solutions 46 | # Solution 1 47 | # class Solution(object): 48 | # def moveZeroes(self, nums): 49 | # cnt = 0 50 | # for i in xrange(len(nums)-1, -1, -1): 51 | # if nums[i] == 0: 52 | # del nums[i] 53 | # cnt += 1 54 | # for j in xrange(cnt): 55 | # nums.append(0) 56 | 57 | #Solution 2 58 | # class Solution(object): 59 | # def moveZeroes(self, nums): 60 | # """ 61 | # :type nums: List[int] 62 | # :rtype: None Do not return anything, modify nums in-place instead. 63 | # """ 64 | # non_zero_index = 0 65 | # i = 0 66 | # for i in range(0,len(nums)): 67 | # if nums[i] != 0: 68 | # nums[non_zero_index] = nums[i] 69 | # non_zero_index += 1 70 | # for i in range(non_zero_index,len(nums)): 71 | # nums[i] = 0 72 | # return nums 73 | 74 | #Solution 3 75 | # class Solution(object): 76 | # def moveZeroes(self, nums): 77 | # zero = 0 # records the position of "0" 78 | # for i in range(len(nums)): 79 | # if nums[i] != 0: 80 | # nums[i], nums[zero] = nums[zero], nums[i] 81 | # zero += 1 82 | 83 | #Solution 4 84 | # class Solution(object): 85 | # def moveZeroes(self, nums): 86 | # """ 87 | # :type nums: List[int] 88 | # :rtype: None Do not return anything, modify nums in-place instead. 89 | # """ 90 | # tail = 0 91 | # for i in range(len(nums)): 92 | # if nums[i] !=0: 93 | # nums[tail],nums[i] = nums[i],nums[tail] 94 | # tail += 1 95 | 96 | 97 | -------------------------------------------------------------------------------- /LeetCode/Product-of-Array-Except-Self.py: -------------------------------------------------------------------------------- 1 | #Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. 2 | 3 | #Example: 4 | 5 | #Input: [1,2,3,4] 6 | #Output: [24,12,8,6] 7 | #Constraint: It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32 bit integer. 8 | 9 | #Note: Please solve it without division and in O(n). 10 | 11 | #Follow up: 12 | #Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.) 13 | 14 | class Solution(object): 15 | def productExceptSelf(self, nums): 16 | """ 17 | :type nums: List[int] 18 | :rtype: List[int 19 | """ 20 | mul = 1 21 | right_side_mul = [] 22 | left_side_mul = [] 23 | for num in reversed(nums): 24 | mul *= num 25 | right_side_mul.append(mul) 26 | right_side_mul.reverse() 27 | 28 | mul = 1 29 | for num in nums: 30 | mul *= num 31 | left_side_mul.append(mul) 32 | 33 | ret = [right_side_mul[1]] 34 | for i, num in enumerate(nums[1:-1]): 35 | try: 36 | ret.append(left_side_mul[i] * right_side_mul[i + 2]) 37 | except: 38 | print(i) 39 | ret.append(left_side_mul[-2]) 40 | return ret 41 | -------------------------------------------------------------------------------- /LeetCode/Single-Numbers.py: -------------------------------------------------------------------------------- 1 | # Single Number 2 | 3 | # Given a non-empty array of integers, every element appears twice except for one. Find that single one. 4 | 5 | # Note: 6 | 7 | # Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 8 | 9 | # Example 1: 10 | 11 | # Input: [2,2,1] 12 | # Output: 1 13 | # Example 2: 14 | 15 | # Input: [4,1,2,1,2] 16 | # Output: 4 17 | 18 | class Solution(object): 19 | def singleNumber(self, nums): 20 | """ 21 | :type nums: List[int] 22 | :rtype: int 23 | """ 24 | x = 0 25 | for i in nums: 26 | x ^= i 27 | return x -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive-Programming 2 | Includes my solutions to some computer science problems from [CodeForces](http://codeforces.com) and [Hackerrank](https://www.hackerrank.com). 3 | ## [CodeForces](http://codeforces.com) 4 | **S.No.** | **Problem Name** | **Solution Link** 5 | ---|:---:|:---: 6 | 1|[(1-A) Theatre-Square.cpp](http://codeforces.com/problemset/problem/1/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/1-A/1A%20Theatre-Square.cpp) 7 | 2|[(4-A) Watermelon.cpp](http://codeforces.com/problemset/problem/4/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/4-A/4A%20Watermelon.cpp) 8 | 3|[(4-C) Registration-System.cpp](https://codeforces.com/problemset/problem/4/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/4-C/4C%20Registration-system.cpp) 9 | 4|[(25-A) IQ-Test.cpp](https://codeforces.com/problemset/problem/4/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/25-A/25A%20IQ-Test.cpp) 10 | 5|[(41-A) Translation.cpp](https://codeforces.com/contest/41/problem/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/41-A/41A%20Translation.cpp) 11 | 6|[(50-A) Domino-Piling.cpp](https://codeforces.com/contest/50/problem/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/50-A/50A%20Domino-piling.cpp) 12 | 7|[(58-A) Chat-Room.cpp](https://codeforces.com/problemset/problem/58/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/58-A/58A%20Chat-room.cpp) 13 | 8|[(59-A) Word.cpp](https://codeforces.com/problemset/problem/59/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/59-A/59A%20Word.cpp) 14 | 9|[(61-A)Ultra-Fast-Mathematician.cpp](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/61-A/61A%20Ultra-Fast-Mathematician.cpp)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/61-A/61A%20Ultra-Fast-Mathematician.cpp) 15 | 10|[(69-A) Young-Physicist.cpp](https://codeforces.com/problemset/problem/69/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/69-A/69A%20Young-Physicist.cpp) 16 | 11|[(71-A) Way-Too-Long-Words.cpp](https://codeforces.com/problemset/problem/71/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/71-A/71A%20Way-Too-Long-Words.cpp) 17 | 12|[(96-A) Football.cpp](https://codeforces.com/problemset/problem/96/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/96-A/96A%20Football.cpp) 18 | 13|[(110-A) Nearly-Lucky-Number.cpp](https://codeforces.com/problemset/problem/110/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/110-A/110A%20Nearly%20Lucky%20Number.cpp) 19 | 14|[(112-A) Petya-and-Strings.cpp](https://codeforces.com/problemset/problem/112/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/112-A/112A%20Petya%20and%20Strings.cpp) 20 | 15|[(116-A) Tram.cpp](https://codeforces.com/problemset/problem/116/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/116-A/116A%20Tram.cpp) 21 | 16|[(118-A) String-Task.cpp](https://codeforces.com/problemset/problem/118/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/118-A/118A%20String-Task.cpp) 22 | 17|[(122-A) Lucky-Division.cpp](https://codeforces.com/problemset/problem/122/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/122-A/122A%20%20Lucky-Division.cpp) 23 | 18|[(131-A) cAPS-lOCK.cpp](https://codeforces.com/problemset/problem/131/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/131-A/131A%20cAPS-lOCK.cpp) 24 | 19|[(148-A) Insomnia-cure.cpp](https://codeforces.com/problemset/problem/148/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/148-A/148A%20Insomnia-cure.cpp) 25 | 20|[(151-A) Soft-Drinking.cpp](https://codeforces.com/problemset/problem/151/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/151-A/151A%20Soft-Drinking.cpp) 26 | 21|[(133-A) HQ9+.cpp](https://codeforces.com/problemset/problem/133/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/133-A/133A%20HQ9%2B.cpp) 27 | 22|[(136-A) Presents.cpp](https://codeforces.com/problemset/problem/136/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/136-A/136A%20Presents.cpp) 28 | 23|[(137-B) Permutation.cpp](https://codeforces.com/problemset/problem/137/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/137-B/137B%20Permutation.cpp) 29 | 24|[(141-A) Amusing-Joke.cpp](https://codeforces.com/problemset/problem/141/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/141-A/141A%20Amusing-Joke.cpp) 30 | 25|[(144-A) Arrival-of-the-General](https://codeforces.com/problemset/problem/144/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/144-A/144A%20Arrival-of-the-General.cpp) 31 | 26|[(155-A) I-love-%username%.cpp](https://codeforces.com/problemset/problem/155/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/155-A/155A%20I_love_%25username%25.cpp) 32 | 27|[(158-A) Next-Round.cpp](https://codeforces.com/problemset/problem/158/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/158-A/158A%20Next-Round.cpp) 33 | 28|[(158-B) Taxi.cpp](https://codeforces.com/problemset/problem/158/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/158-B/158B%20Taxi.cpp) 34 | 29|[(160-A) Twins.cpp](https://codeforces.com/problemset/problem/160/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/160-A/160A%20Twins.cpp) 35 | 30|[(189-A) Cut-Ribbon.cpp](https://codeforces.com/problemset/problem/189/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/189-A/189A%20Cut-Ribbon.cpp) 36 | 31|[(200-B) Drinks.cpp](https://codeforces.com/problemset/problem/200/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/200-B/200B%20Drinks.cpp) 37 | 32|[(208-A) Dubstep.cpp](https://codeforces.com/problemset/problem/208/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/208-A/208A%20Dubstep.cpp) 38 | 33|[(231-A) Team.cpp](https://codeforces.com/problemset/problem/231/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/231-A/231A%20Team.cpp) 39 | 34|[(236-A) Boy-or-Girl.cpp](https://codeforces.com/problemset/problem/236/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/236-A/236A%20Boy-or-Girl.cpp) 40 | 35|[(259-A) Little-Elephant-and-Chess.cpp](https://codeforces.com/problemset/problem/259/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/259-A/259A%20Little-Elephant-and-Chess.cpp) 41 | 36|[(263-A) Beautiful-Matrix.cpp](https://codeforces.com/problemset/problem/263/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/263-A/263A%20Beautiful-Matrix.cpp) 42 | 37|[(266-A) Stones-on-the-Table.cpp](https://codeforces.com/problemset/problem/266/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/266-A/266A%20Stones-on-the-Table.cpp) 43 | 38|[(266-B) Queue-at-the-School.cpp](https://codeforces.com/problemset/problem/266/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/266-B/266B%20Queue-at-the-School.cpp) 44 | 39|[(271-A) Beautiful-Year.cpp](https://codeforces.com/problemset/problem/271/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/271-A/271A%20Beautiful-Year.cpp) 45 | 40|[(276-A) Lunch-Rush.cpp](https://codeforces.com/problemset/problem/276/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/276-A/276A%20Lunch-Rush.cpp) 46 | 41|[(281-A) Word-Capitalization.cpp](https://codeforces.com/problemset/problem/281/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/281-A/281A%20Word-Capitalization.cpp) 47 | 42|[(282-A) Bit++.cpp](https://codeforces.com/problemset/problem/282/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/282-A/282A%20Bit%2B%2B.cpp) 48 | 43|[(313-A) Ilya-and-Bank-Account.cpp](https://codeforces.com/problemset/problem/313/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/313-A/313A%20Ilya-and-Bank-Account.cpp) 49 | 44|[(318-A) Even-Odds.cpp](https://codeforces.com/problemset/problem/318/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/318-A/318A%20Even-Odds.cpp) 50 | 45|[(320-A) Magic-Numbers.cpp](https://codeforces.com/problemset/problem/320/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/320-A/320A%20Magic-Numbers.cpp) 51 | 46|[(327-A) Flipping-Game.cpp](https://codeforces.com/problemset/problem/327/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/327-A/327A%20%20Flipping-Game.cpp) 52 | 47|[(337-A) Puzzles.cpp](https://codeforces.com/problemset/problem/337/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/337-A/337A%20Puzzles.cpp) 53 | 48|[(339-A) Helpful-Maths.cpp](https://codeforces.com/problemset/problem/339/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/339-A/339A%20Helpful-Maths.cpp) 54 | 49|[(339-B) Xenia-and-Ringroad.cpp](https://codeforces.com/problemset/problem/339/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/339-B/339B%20Xenia-and-Ringroad.cpp) 55 | 50|[(344-A) Magnets.cpp](https://codeforces.com/problemset/problem/344/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/344-A/344A%20Magnets.cpp) 56 | 51|[(384-A) Coder.cpp](https://codeforces.com/problemset/problem/384/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/384-A/384A%20Coder.cpp) 57 | 52|[401-A) Vanya-and-Cards.cpp](https://codeforces.com/problemset/problem/401/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/401-A/401A%20Vanya-and-Cards.cpp) 58 | 53|[(405-A) Gravity-Flip.cpp](https://codeforces.com/problemset/problem/405/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/405-A/405A%20Gravity-Flip.cpp) 59 | 54|[(451-A) Game-With-Sticks.cpp](https://codeforces.com/problemset/problem/451/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/451-A/451A%20Game-With-Sticks.cpp) 60 | 55|[(460-A) Vasya-and-Socks.cpp](https://codeforces.com/problemset/problem/460/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/460-A/460A%20Vasya-and-Socks.cpp) 61 | 56|[(467-A) George-and-Accommodation.cpp](https://codeforces.com/problemset/problem/467/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/467-A/467A%20George-and-Accommodation.cpp) 62 | 57|[(467-B) Fedor-and-New-Game.cpp](https://codeforces.com/problemset/problem/467/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/467-B/467B%20Fedor-and-New-Game.cpp) 63 | 58|[(469-A) I-Wanna-Be-the-Guy.cpp](https://codeforces.com/problemset/problem/469/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/469-A/469A%20%20I-Wanna-Be-the-Guy.cpp) 64 | 59|[(472-A) Design-Tutorial-Learn-from-Math.cpp](https://codeforces.com/problemset/problem/472/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/472-A/472A%20Design-Tutorial-Learn-from-Math.cpp) 65 | 60|[(479-A) Expression.cpp](https://codeforces.com/problemset/problem/479/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/479-A/479A%20Expression.cpp) 66 | 61|[(486-A) Calculating-Function.cpp](https://codeforces.com/problemset/problem/486/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/486-A/486A%20Calculating-Function.cpp) 67 | 62|[(520-A) Pangram.cpp](https://codeforces.com/problemset/problem/520/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/520-A/520A%20Pangram.cpp) 68 | 63|[(546-A)Soldier-and-Bananas.cpp](https://codeforces.com/problemset/problem/546/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/546-A/546A%20Soldier-and-Bananas.cpp) 69 | 64|[(580-A) Kefa-and-First-Steps.cpp](https://codeforces.com/problemset/problem/580/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/580-A/580A%20Kefa-and-First-Steps.cpp) 70 | 65|[(705-A) Hulk.cpp](https://codeforces.com/problemset/problem/705/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/705-A/705A%20Hulk.cpp) 71 | 66|[(710-A) King-Moves.cpp](https://codeforces.com/problemset/problem/710/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/710-A/710A%20King%20Moves.cpp) 72 | 67|[(710-B) Optimal-Point-on-a-Line.cpp](https://codeforces.com/problemset/problem/710/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/710-B/710B%20Optimal-Point-on-a-Line.cpp) 73 | 68|[(780-B) Andryusha-and-Socks.cpp](https://codeforces.com/problemset/problem/780/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/780-A/780A%20Andryusha-and-Socks.cpp) 74 | 69|[(784-A) Numbers-Joke.cpp](https://codeforces.com/contest/784/problem/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/784-A/784A%20Numbers-Joke.cpp) 75 | 70|[(884-A) Book-Reading.cpp](https://codeforces.com/problemset/problem/884/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/884-A/884A%20Book%20Reading.cpp) 76 | 71|[(884-B) Japanese-Crosswords-Strike-Back.cpp](https://codeforces.com/problemset/problem/884/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/884-B/884B%20Japanese%20Crosswords%20Strike%20Back.cpp) 77 | 72|[(893-A) Chess-For-Three.cpp](https://codeforces.com/problemset/problem/893/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/893-A/893A%20Chess%20For%20Three.cpp) 78 | 73|[(893-B) Beautiful-Divisors.cpp](https://codeforces.com/problemset/problem/893/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/893-A/893A%20Chess%20For%20Three.cpp) 79 | 74|[(894-A) QAQ.cpp](https://codeforces.com/problemset/problem/894/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/894-A/894%20QAQ.cpp) 80 | 75|[(922-A) Cloning-Toys.cpp](https://codeforces.com/problemset/problem/922/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/922-A/922A%20Cloning%20Toys.cpp) 81 | 76|[(922-B) Magic-Forest.cpp](https://codeforces.com/problemset/problem/922/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/922-B/922B%20Magic%20Forest.cpp) 82 | 77|[(938-A) Word-Correction.cpp](https://codeforces.com/problemset/problem/938/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/938-A/938A%20Word%20Correction.cpp) 83 | 78|[(938-B) Run-For-Your-Prize.cpp](https://codeforces.com/problemset/problem/938/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/938-B/938B%20Run%20For%20Your%20Prize.cpp) 84 | 79|[(939-A) Love-Triangle.cpp](https://codeforces.com/problemset/problem/939/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/939-A/939A%20Love%20Triangle.cpp) 85 | 80|[(939-B) Hamster-Farm.cpp](https://codeforces.com/problemset/problem/939/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/939-B/939B%20Hamster%20Farm.cpp) 86 | 81|[(898-A) Rounding.cpp](https://codeforces.com/problemset/problem/898/A)|[solution]() 87 | 82|[(898-B) Proper-Nutrition.cpp](https://codeforces.com/problemset/problem/898/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/898-B/898B%20Proper%20Nutrition.cpp) 88 | 83|[(900-A) Find-Extra-One.cpp](https://codeforces.com/problemset/problem/900/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/900-A/900A%20Find%20Extra%20One.cpp) 89 | 84|[(900-B) Position-in-Fraction.cpp](https://codeforces.com/problemset/problem/900/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/900-B/900B%20Position%20in%20Fraction.cpp) 90 | 85|[(903-A) Hungry-Student-Problem.cpp](https://codeforces.com/problemset/problem/903/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/903-A/903A%20Hungry%20Student%20Problem.cpp) 91 | 86|[(903-B) The-Modcrab.cpp](https://codeforces.com/problemset/problem/903/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/903-B/%20903B%20The%20Modcrab.cpp) 92 | 87|[(903-C) Boxes-Packing.cpp](https://codeforces.com/problemset/problem/903/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/903-C/903C%20Boxes%20Packing.cpp) 93 | 88|[(908-A) New-Year-and-Counting Cards.cpp](https://codeforces.com/problemset/problem/908/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/908-A/908A%20New%20Year%20and%20Counting%20Cards.cpp) 94 | 89|[(908-B) New-Year-and-Buggy-Bot.cpp](https://codeforces.com/problemset/problem/908/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/908-B/908B%20New%20Year%20and%20Buggy%20Bot.cpp) 95 | 90|[(908-C) New-Year-and-Curling.cpp](https://codeforces.com/problemset/problem/908/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/908-C/908C%20New%20Year%20and%20Curling.cpp) 96 | 91|[(911-A)Nearest Minimums.cpp](https://codeforces.com/problemset/problem/911/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/911-A/911A%20Nearest%20Minimums.cpp) 97 | 92|[(913-A)Modular Exponentiation.cpp](https://codeforces.com/problemset/problem/913/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/913-A/913A%20Modular%20Exponentiation.cpp) 98 | 93|[(915-B)Browser.cpp](https://codeforces.com/problemset/problem/915/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/915-B/915B%20Browser.cpp) 99 | 94|[(915-C)Permute Digits.cpp](https://codeforces.com/problemset/problem/915/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/915-C/915C%20Permute%20Digits.cpp) 100 | 95|[(916-A)Jamie and Alarm Snooze.cpp](https://codeforces.com/problemset/problem/916/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/916-A/916A%20Jamie%20and%20Alarm%20Snooze.cpp) 101 | 96|[(918-A)Eleven.cpp](https://codeforces.com/problemset/problem/918/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/918-A/918A%20Eleven.cpp) 102 | 97|[(918-B)Radio Station.cpp](https://codeforces.com/problemset/problem/918/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/918-B/918B%20Radio%20Station.cpp) 103 | 98|[(919-A)Supermarket.cpp](https://codeforces.com/problemset/problem/919/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/919-A/919A%20Supermarket.cpp) 104 | 99|[(919-B)Perfect Number.cpp](https://codeforces.com/problemset/problem/919/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/919-B/919B%20Perfect%20Number.cpp) 105 | 100|[(919-C)Seat Arrangements.cpp](https://codeforces.com/problemset/problem/919/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/919-C/919C%20Seat%20Arrangements.cpp) 106 | 101|[(920-A)Water The Garden.cpp](https://codeforces.com/problemset/problem/920/A)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/920-A/920A%20Water%20The%20Garden.cpp) 107 | 102|[(920-B)Tea Queue.cpp](https://codeforces.com/problemset/problem/920/B)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/920-B/920B%20Tea%20Queue.cpp) 108 | 103|[(920-C)Swap Adjacent Elements.cpp](https://codeforces.com/problemset/problem/920/C)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/Code%20Forces/920-C/920C%20Swap%20Adjacent%20Elements.cpp) 109 | 110 | ## [LeetCode](https://leetcode.com/) 111 | The first 30 questions listed on this table are the questions that came up on LeetCode April Challenge 2020. 112 | **Days** | **Problem Name** | **Solution Link** 113 | ---|:---:|:---: 114 | Day 1|[Single-Numbers.py](https://leetcode.com/problems/single-number/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Single-Numbers.py) 115 | Day 2|[Happy-Number.py](https://leetcode.com/problems/happy-number/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Happy-Number.py) 116 | Day 3|[Maximum-Subarray.py](https://leetcode.com/problems/maximum-subarray/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Maximum-Subarray.py) 117 | Day 4|[Move-Zeroes.py](https://leetcode.com/problems/move-zeroes/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Move-Zeroes.py) 118 | Day 5|[Best-Time-to-Buy-and-Sell-Stock-II.py](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Best-Time-to-Buy-and-Sell-Stock-II.py) 119 | Day 6|[Group-Anagrams.py](https://leetcode.com/problems/group-anagrams/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Group-Anagrams.py) 120 | Day 7|[Counting-Elements.py](https://leetcode.com/problems/counting-elements/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Counting-Elements.py) 121 | Day 8|[Middle-of-the-Linked-List.py](https://leetcode.com/problems/middle-of-the-linked-list/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Middle-of-the-Linked-List.py) 122 | Day 9|[Backspace-String-Compare.py](https://leetcode.com/problems/backspace-string-compare/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Backspace-String-Compare.py) 123 | Day 10|[Min-Stack.py](https://leetcode.com/problems/min-stack/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Min-Stackpy.py) 124 | Day 11|[Diameter-of-Binary-Tree.py](https://leetcode.com/problems/diameter-of-binary-tree/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Diameter-of-Binary-Tree.py) 125 | Day 12|[Last-Stone-Weight.py](https://leetcode.com/problems/last-stone-weight/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Last-Stone-Weight.py) 126 | Day 13|[Contiguous-Array.py](https://leetcode.com/problems/contiguous-array/)|[solution](https://github.com/canxkoz/Competitive-Programming/blob/master/LeetCode/Contiguous-Array.py) 127 | --------------------------------------------------------------------------------