├── .gitignore ├── CodeForces ├── 110A.cpp ├── 112A.cpp ├── 1154A.cpp ├── 1335A.cpp ├── 1352A.py ├── 1399A.cpp ├── 1409A.py ├── 141A.cpp ├── 144A.cpp ├── 1512A.py ├── 1560A.py ├── 160A.cpp ├── 1669A.py ├── 1676A.py ├── 1692A.py ├── 1703A.cpp ├── 1742A.cpp ├── 1807A.py ├── 1850A.cpp ├── 1999A.cpp ├── 266A.cpp ├── 271A.py ├── 339A.cpp ├── 344A.cpp ├── 381A.py ├── 432A.py ├── 469A.cpp ├── 486A.cpp ├── 490A.py ├── 50A.py ├── 546A.cpp ├── 59A.cpp ├── 630A.cpp ├── 703A.py ├── 705A.cpp ├── 723A.cpp ├── 734A.cpp ├── 758A.py ├── 791A.cpp ├── 996A.cpp └── contests │ └── 2036 │ └── A.cpp ├── HackerRank ├── Python │ ├── arithmetic_operators.py │ ├── division.py │ ├── find_runner_up_score.py │ ├── if_else.py │ ├── loops.py │ ├── print_function.py │ ├── say_hello_world.py │ └── write_a_function.py └── compare_the_triplets.py ├── LeetCode ├── 1.cpp ├── 1.py ├── 12.py ├── 125.py ├── 14.py ├── 1470.py ├── 168.py ├── 169.py ├── 17.py ├── 171.py ├── 1732find_the_highest_altitude.py ├── 2.py ├── 206.py ├── 21.py ├── 225.py ├── 231.py ├── 238product_of_array_except_self.py ├── 26.py ├── 27RemoveElement.cpp ├── 326.py ├── 342.py ├── 344.py ├── 345.py ├── 35.py ├── 3512.py ├── 383.py ├── 392.py ├── 409.py ├── 412.py ├── 415.py ├── 441.py ├── 442_find_all_duplicates.py ├── 445.py ├── 448.py ├── 5.py ├── 500.py ├── 7.py ├── 82.py ├── 83.py ├── 88.py ├── 9PalindromeNumber.py ├── LeetCode75 │ └── 724find_pivot_index.py ├── StudyPlan │ └── ProgrammingSkills │ │ ├── 13.py │ │ ├── 1502.py │ │ ├── 1768.py │ │ ├── 1822.py │ │ ├── 242.py │ │ ├── 28.py │ │ ├── 283.py │ │ ├── 389.py │ │ ├── 459.py │ │ ├── 58.py │ │ ├── 66.py │ │ └── 709.py └── longestCommonPrefix.cpp ├── README.md ├── beecrowd └── BEGINNER │ ├── 1000.py │ ├── 1001.py │ ├── 1002.py │ ├── 1003.py │ ├── 1004.py │ ├── 1005.py │ ├── 1006.py │ ├── 1007.py │ ├── 1008.py │ ├── 1009.py │ ├── 1010.py │ └── 1011.py ├── faster_io_methods.py └── input_methods_for_cp.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /CodeForces/110A.cpp: -------------------------------------------------------------------------------- 1 | // Nearly Lucky Number 2 | 3 | #include 4 | using namespace std; 5 | 6 | #define ll long long 7 | 8 | int main() 9 | { 10 | ll n; cin>> n; 11 | 12 | int ans = 0; 13 | while (n != 0) { 14 | int digit = n % 10; 15 | 16 | if (digit == 4 || digit == 7) { 17 | ans++; 18 | } 19 | n = n / 10; 20 | } 21 | 22 | if (ans == 4 || ans == 7) { 23 | cout << "YES" << endl; 24 | } else { 25 | cout << "NO" << endl; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CodeForces/112A.cpp: -------------------------------------------------------------------------------- 1 | // Petya and Strings 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s1, s2; cin>> s1>> s2; 11 | 12 | transform(s1.begin(), s1.end(), s1.begin(), ::tolower); 13 | transform(s2.begin(), s2.end(), s2.begin(), ::tolower); 14 | 15 | int comp = s1.compare(s2); 16 | 17 | if(comp == 0) { 18 | cout<< 0<< endl; 19 | } else if(comp < 0) { 20 | cout<< -1<< endl; 21 | } else { 22 | cout<< 1<< endl; 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CodeForces/1154A.cpp: -------------------------------------------------------------------------------- 1 | // Restoring Three Numbers 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | vector restoreThreeNums(int x1, int x2, int x3, int x4) { 9 | vector nums; 10 | vector sums = {x1, x2, x3, x4}; 11 | 12 | // a+b+c 13 | int sumAll = *max_element(sums.begin(), sums.end()); 14 | 15 | sums.erase(remove(sums.begin(), sums.end(), sumAll), sums.end()); 16 | 17 | int a = sumAll - sums[0]; 18 | int b = sumAll - sums[1]; 19 | int c = sumAll - sums[2]; 20 | 21 | nums.push_back(a); 22 | nums.push_back(b); 23 | nums.push_back(c); 24 | 25 | return nums; 26 | } 27 | 28 | int main() { 29 | int x1, x2, x3, x4; 30 | cin>> x1>> x2>> x3>> x4; 31 | 32 | vector result = restoreThreeNums(x1, x2, x3, x4); 33 | 34 | if (!result.empty()) { 35 | cout<< result[0]<< " "<< result[1]<< " "< 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int t; cin>> t; 24 | while(t >= 1) { 25 | int n; cin>>n; 26 | if(n>2) { 27 | n%2==0 ? cout<< n/2-1<< endl : cout<< n/2< 0: 17 | remainder = integer % count 18 | if remainder != 0: 19 | ans.append(remainder) 20 | integer = integer - (remainder) 21 | count *= 10 22 | 23 | sys.stdout.write(f'{len(ans)}\n') 24 | sys.stdout.write(f' '.join(map(str, ans)) + '\n') 25 | 26 | -------------------------------------------------------------------------------- /CodeForces/1399A.cpp: -------------------------------------------------------------------------------- 1 | // Remove Smallest 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int t; cin>> t; 24 | int n; 25 | while (t--) 26 | { 27 | cin>> n; 28 | vi v(n); 29 | rep(i, 0, n) cin>> v[i]; 30 | 31 | sort(v.begin(), v.end()); 32 | bool result = true; 33 | 34 | rep(i, 0, n-1) { 35 | if(v[i+1] - v[i] > 1) { 36 | result = false; 37 | break; 38 | } 39 | } 40 | if(result) cout<< "YES"<< endl; 41 | else cout<< "NO"<< endl; 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /CodeForces/1409A.py: -------------------------------------------------------------------------------- 1 | # Yet Another Two Integers Problem 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split('\n') 6 | 7 | # integer = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] 8 | 9 | t = int(input[0].strip()) 10 | index = 1 11 | 12 | for _ in range(t): 13 | # arr = list(map(int, input[index].strip().split())) 14 | # index += 1 15 | # 16 | # diff = abs(arr[0] - arr[1]) 17 | # ans = 0 18 | # for i in integer: 19 | # if diff >= i: 20 | # ans += (diff // i) 21 | # diff -= (diff // i) * i 22 | # 23 | # sys.stdout.write(f'{ans}\n') 24 | 25 | a, b = map(int, input[index].strip().split()) 26 | index += 1 27 | 28 | diff = abs(a - b) 29 | ans = (diff + 9) // 10 30 | sys.stdout.write(f'{ans}\n') 31 | -------------------------------------------------------------------------------- /CodeForces/141A.cpp: -------------------------------------------------------------------------------- 1 | // Amusing Joke 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | bool solve(string guest, string host, string pile) { 9 | if ((guest.length() + host.length()) != pile.length()) { 10 | return false; 11 | } 12 | 13 | unordered_map guestFreq, hostFreq, pileFreq; 14 | for (char c: guest) guestFreq[c]++; 15 | for (char c: host) hostFreq[c]++; 16 | for (char c: pile) pileFreq[c]++; 17 | 18 | unordered_map:: iterator it; 19 | for (it=pileFreq.begin(); it!=pileFreq.end(); it++) { 20 | it->second -= guestFreq[it->first]; 21 | it->second -= hostFreq[it->first]; 22 | 23 | if (it->second > 0) return false; 24 | if (guestFreq[it->first] < 0 || hostFreq[it->first] < 0) return false; 25 | } 26 | return true; 27 | } 28 | 29 | int main() { 30 | string guest, host, pile; 31 | cin>> guest>> host>> pile; 32 | 33 | bool result = solve(guest, host, pile); 34 | if (result) cout<< "YES"<< endl; 35 | else cout<< "NO"<< endl; 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /CodeForces/144A.cpp: -------------------------------------------------------------------------------- 1 | // Arrival of the General 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int n; cin>> n; 24 | vi v(n); 25 | rep(i, 0, n) { 26 | cin>> v[i]; 27 | } 28 | int ans = 0; 29 | auto max = max_element(v.begin(), v.end()); 30 | auto min = min_element(v.rbegin(), v.rend()); 31 | int maxElementDistance = distance(v.begin(), max); 32 | int minElementDistance = n - distance(v.rbegin(), min) - 1; 33 | 34 | if(maxElementDistance >= minElementDistance) { 35 | ans = ans + maxElementDistance + (n-1-minElementDistance) - 1; 36 | } else { 37 | ans = ans + maxElementDistance + (n-1-minElementDistance); 38 | } 39 | cout<< ans<< endl; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /CodeForces/1512A.py: -------------------------------------------------------------------------------- 1 | # Spy Detected! 2 | 3 | import sys 4 | from collections import Counter 5 | 6 | input = sys.stdin.read().strip().split('\n') 7 | 8 | t = int(input[0].strip()) 9 | index = 1 10 | 11 | for _ in range(t): 12 | n = int(input[index].strip()) 13 | index += 1 14 | arr = list(map(int, input[index].strip().split())) 15 | index += 1 16 | 17 | # s = set(arr) 18 | # a, b = iter(s) 19 | # 20 | # if arr.count(a) < arr.count(b): 21 | # sys.stdout.write(f'{arr.index(a) + 1}\n') 22 | # else: 23 | # sys.stdout.write(f'{arr.index(b) + 1}\n') 24 | 25 | counts = Counter(arr) 26 | unique = [num for num, count in counts.items() if count == 1][0] 27 | 28 | sys.stdout.write(f'{arr.index(unique) + 1}\n') 29 | -------------------------------------------------------------------------------- /CodeForces/1560A.py: -------------------------------------------------------------------------------- 1 | # Dislike of Threes 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split('\n') 6 | 7 | t = int(input[0]) 8 | 9 | integers = list(map(int, input[1:])) 10 | ans = [1] * t 11 | 12 | for i in range(t): 13 | count, current_integer = 1, 1 14 | 15 | while count <= integers[i]: 16 | if not ((current_integer % 3 == 0) or (current_integer % 10 == 3)): 17 | count += 1 18 | ans[i] = current_integer 19 | current_integer += 1 20 | 21 | sys.stdout.write(f'\n'.join(map(str, ans))) 22 | -------------------------------------------------------------------------------- /CodeForces/160A.cpp: -------------------------------------------------------------------------------- 1 | // Twins 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int n; cin>> n; 24 | vi v(n); 25 | int total = 0; 26 | rep(i, 0, n) { 27 | cin>> v[i]; 28 | total += v[i]; 29 | } 30 | 31 | int ans = 0, pick = 0; 32 | sort(v.rbegin(), v.rend()); 33 | int i=0; 34 | while(pick <= total && i < n) { 35 | pick += v[i]; 36 | total -= v[i]; 37 | ans++; 38 | i++; 39 | } 40 | cout<< ans<< endl; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /CodeForces/1669A.py: -------------------------------------------------------------------------------- 1 | # Division? 2 | 3 | import sys 4 | 5 | t = int(sys.stdin.readline().strip()) 6 | for i in range(t): 7 | rating = int(sys.stdin.readline().strip()) 8 | 9 | if rating <= 1399: 10 | sys.stdout.write('Division 4\n') 11 | elif 1400 <= rating <= 1599: 12 | sys.stdout.write('Division 3\n') 13 | elif 1600 <= rating <= 1899: 14 | sys.stdout.write('Division 2\n') 15 | else: 16 | sys.stdout.write('Division 1\n') 17 | -------------------------------------------------------------------------------- /CodeForces/1676A.py: -------------------------------------------------------------------------------- 1 | # Lucky? 2 | 3 | import sys 4 | 5 | t = int(sys.stdin.readline().strip()) 6 | for i in range(t): 7 | ticket_digits = list(map(int, sys.stdin.readline().strip())) 8 | if sum(ticket_digits[:3]) == sum(ticket_digits[3:]): 9 | sys.stdout.write('YES\n') 10 | else: 11 | sys.stdout.write('NO\n') 12 | -------------------------------------------------------------------------------- /CodeForces/1692A.py: -------------------------------------------------------------------------------- 1 | # Marathon 2 | 3 | t = int(input()) 4 | for i in range(t): 5 | distinct_integers = [int(i) for i in input().split()] 6 | 7 | print(len([i for i in distinct_integers if i > distinct_integers[0]])) 8 | 9 | # Input 10 | # 4 11 | # 2 3 4 1 12 | # 10000 0 1 2 13 | # 500 600 400 300 14 | # 0 9999 10000 9998 15 | 16 | # Output 17 | # 2 18 | # 0 19 | # 1 20 | # 3 21 | -------------------------------------------------------------------------------- /CodeForces/1703A.cpp: -------------------------------------------------------------------------------- 1 | // YES or YES? 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int t; cin>> t; 24 | vector v(t); 25 | 26 | rep(i, 0, t) { 27 | cin>> v[i]; 28 | transform(v[i].begin(), v[i].end(), v[i].begin(), ::tolower); 29 | 30 | if(v[i] == "yes") cout<< "YES"<< endl; 31 | else cout<< "NO"<< endl; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /CodeForces/1742A.cpp: -------------------------------------------------------------------------------- 1 | // Sum 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | #define vi vector 14 | #define pii pair 15 | #define vii vector 16 | #define rep(i,a,b) for(int i=a; i=b; i--) 18 | #define for_each(x,y) for(auto &x : y) 19 | #define pb push_back 20 | #define ff first 21 | #define ss second 22 | 23 | int main() 24 | { 25 | int t; cin>> t; 26 | 27 | while (t--) 28 | { 29 | vi v(3); 30 | for_each(x, v) cin>> x; 31 | 32 | auto largest = max_element(v.begin(), v.end()); 33 | int sum = accumulate(v.begin(), v.end(), 0); 34 | 35 | if(sum == *largest * 2) cout<< "YES"<< endl; 36 | else cout<< "NO"<< endl; 37 | } 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /CodeForces/1807A.py: -------------------------------------------------------------------------------- 1 | # Plus or Minus 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split('\n') 6 | 7 | t = int(input[0].strip()) 8 | index = 1 9 | 10 | for _ in range(t): 11 | a, b, c = map(int, input[index].strip().split()) 12 | index += 1 13 | 14 | if a + b == c: 15 | sys.stdout.write('+\n') 16 | else: 17 | sys.stdout.write('-\n') 18 | -------------------------------------------------------------------------------- /CodeForces/1850A.cpp: -------------------------------------------------------------------------------- 1 | // To My Critics 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t; cin>> t; 8 | int digits[3]; 9 | while (t--) 10 | { 11 | cin>> digits[0]>> digits[1]>> digits[2]; 12 | if (digits[0]+digits[1]>=10 || digits[0]+digits[2]>=10 || digits[1]+digits[2]>=10) cout<< "YES"<< endl; 13 | else cout<< "NO"<< endl; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /CodeForces/1999A.cpp: -------------------------------------------------------------------------------- 1 | // A+B Again? 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t; 8 | cin>> t; 9 | while (t--) { 10 | int num; 11 | cin>> num; 12 | cout<< (num % 10) + ((num / 10) % 10)<< endl; 13 | } 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /CodeForces/266A.cpp: -------------------------------------------------------------------------------- 1 | // Stones on the table 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; cin>> n; 9 | string s; cin>> s; 10 | 11 | char c = s[0]; 12 | int ans = 0; 13 | for(int i=1; i 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | #define vi vector 13 | #define vs vector 14 | #define vc vector 15 | #define pii pair 16 | #define vii vector 17 | #define rep(i,a,b) for(int i=a; i=b; i--) 19 | #define for_each(x,y) for(auto &x : y) 20 | #define pb push_back 21 | #define ff first 22 | #define ss second 23 | 24 | int main() 25 | { 26 | string s; cin>> s; 27 | 28 | vc v; 29 | for_each(ch, s) { 30 | if(ch != '+') { 31 | v.pb(ch); 32 | } 33 | } 34 | 35 | sort(v.begin(), v.end()); 36 | rep(i, 0, v.size()) { 37 | cout<< v[i]; 38 | if(i != v.size() - 1) { 39 | cout<< "+"; 40 | } 41 | } 42 | cout<< endl; 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /CodeForces/344A.cpp: -------------------------------------------------------------------------------- 1 | // Magnets 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | #define vi vector 13 | #define pii pair 14 | #define vii vector 15 | #define rep(i,a,b) for(int i=a; i=b; i--) 17 | #define for_each(x,y) for(auto &x : y) 18 | #define pb push_back 19 | #define ff first 20 | #define ss second 21 | 22 | int main() 23 | { 24 | int n; cin>> n; 25 | vi v(n); 26 | rep(i, 0, n) { 27 | cin>> v[i]; 28 | } 29 | 30 | int ans = 1, prev=v[0]; 31 | rep(i, 1, n) { 32 | if(v[i] != prev) { 33 | ans++; 34 | prev = v[i]; 35 | } 36 | } 37 | 38 | cout<< ans<< endl; 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /CodeForces/381A.py: -------------------------------------------------------------------------------- 1 | # Sereja and Dima 2 | 3 | import sys 4 | 5 | n = int(sys.stdin.readline().strip()) 6 | cards = list(map(int, sys.stdin.readline().strip().split())) 7 | 8 | l, r = 0, n - 1 9 | sereja, dima = 0, 0 10 | 11 | seraja_turn = True 12 | while l <= r: 13 | if cards[r] > cards[l]: 14 | if seraja_turn: 15 | sereja += cards[r] 16 | else: 17 | dima += cards[r] 18 | r -= 1 19 | else: 20 | if seraja_turn: 21 | sereja += cards[l] 22 | else: 23 | dima += cards[l] 24 | l += 1 25 | 26 | seraja_turn = not seraja_turn 27 | 28 | # for i in range(n): 29 | # if i % 2 == 0: 30 | # if cards[r] >= cards[l]: 31 | # sereja += cards[r] 32 | # r -= 1 33 | # else: 34 | # sereja += cards[l] 35 | # l += 1 36 | # else: 37 | # if cards[r] >= cards[l]: 38 | # dima += cards[r] 39 | # r -= 1 40 | # else: 41 | # dima += cards[l] 42 | # l += 1 43 | 44 | sys.stdout.write(f'{sereja} {dima}') 45 | -------------------------------------------------------------------------------- /CodeForces/432A.py: -------------------------------------------------------------------------------- 1 | # Choosing Teams 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split('\n') 6 | 7 | t, k = map(int, input[0].strip().split()) 8 | participation = list(map(int, input[1].strip().split())) 9 | 10 | # eligible = 0 11 | # for x in participation: 12 | # if 5 - x >= k: 13 | # eligible += 1 14 | 15 | eligible = len([x for x in participation if 5 - x >= k]) 16 | 17 | sys.stdout.write(f'{eligible // 3}\n') 18 | -------------------------------------------------------------------------------- /CodeForces/469A.cpp: -------------------------------------------------------------------------------- 1 | // I Wanna Be the Guy 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #define vi vector 11 | #define pii pair 12 | #define vii vector 13 | #define rep(i,a,b) for(int i=a; i=b; i--) 15 | #define for_each(x,y) for(auto &x : y) 16 | #define pb push_back 17 | #define ff first 18 | #define ss second 19 | 20 | int main() 21 | { 22 | int n; cin>> n; 23 | int p1; cin>> p1; 24 | vi v1(p1); 25 | rep(i, 0, v1.size()) { 26 | cin>> v1[i]; 27 | } 28 | int p2; cin>> p2; 29 | vi v2(p2); 30 | rep(i, 0, v2.size()) { 31 | cin>> v2[i]; 32 | } 33 | 34 | vi allLevels; 35 | allLevels.insert(allLevels.end(), v1.begin(), v1.end()); 36 | allLevels.insert(allLevels.end(), v2.begin(), v2.end()); 37 | 38 | sort(allLevels.begin(), allLevels.end()); 39 | auto it = unique(allLevels.begin(), allLevels.end()); 40 | allLevels.erase(it, allLevels.end()); 41 | 42 | if(allLevels.size() == n) { 43 | cout<< "I become the guy."<< endl; 44 | } else { 45 | cout<< "Oh, my keyboard!"<< endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /CodeForces/486A.cpp: -------------------------------------------------------------------------------- 1 | // Calculating Function 2 | 3 | #include 4 | using namespace std; 5 | 6 | #define ll long long 7 | 8 | int main() 9 | { 10 | ll n; cin>> n; 11 | 12 | ll ans = 0; 13 | if(n % 2 == 0) { 14 | ans = n / 2; 15 | } else { 16 | ans = ((n+1)/2) * (-1); 17 | } 18 | cout<< ans<< endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /CodeForces/490A.py: -------------------------------------------------------------------------------- 1 | # Team Olympiad 2 | import sys 3 | 4 | input = sys.stdin.read().strip().split() 5 | 6 | n = int(input[0]) 7 | skills = list(map(int, input[1:])) 8 | 9 | one, two, three = [], [], [] 10 | 11 | for index, skill in enumerate(skills): 12 | if skill == 1: 13 | one.append(index + 1) 14 | elif skill == 2: 15 | two.append(index + 1) 16 | else: 17 | three.append(index + 1) 18 | 19 | min_len = min(len(one), len(two), len(three)) 20 | sys.stdout.write(f'{min_len}\n') 21 | for i in range(min_len): 22 | sys.stdout.write(f'{one[i]} {two[i]} {three[i]}\n') 23 | -------------------------------------------------------------------------------- /CodeForces/50A.py: -------------------------------------------------------------------------------- 1 | # Domino piling 2 | 3 | import sys 4 | 5 | M, N = map(int, sys.stdin.readline().strip().split()) 6 | sys.stdout.write(f'{(M * N) // 2}') 7 | -------------------------------------------------------------------------------- /CodeForces/546A.cpp: -------------------------------------------------------------------------------- 1 | // Soldier and Bananas 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | #define vi vector 13 | #define vs vector 14 | #define vc vector 15 | #define pii pair 16 | #define vii vector 17 | #define rep(i,a,b) for(int i=a; i=b; i--) 19 | #define for_each(x,y) for(auto &x : y) 20 | #define pb push_back 21 | #define ff first 22 | #define ss second 23 | 24 | int main() 25 | { 26 | int k, n, w; cin>> k>> n>> w; 27 | 28 | int totalCost = 0; 29 | rep(i, 1, w+1) { 30 | totalCost += (i * k); 31 | } 32 | 33 | int ans = totalCost - n; 34 | if(ans <= 0) { 35 | cout<< 0<< endl; 36 | } else { 37 | cout<< ans<< endl; 38 | } 39 | 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /CodeForces/59A.cpp: -------------------------------------------------------------------------------- 1 | // Word 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; cin>> s; 10 | 11 | int u=0, l=0; 12 | for(auto c : s) { 13 | if(isupper(c)) { 14 | u++; 15 | } else { 16 | l++; 17 | } 18 | } 19 | 20 | if(l >= u) { 21 | transform(s.begin(), s.end(), s.begin(), ::tolower); 22 | } else { 23 | transform(s.begin(), s.end(), s.begin(), ::toupper); 24 | } 25 | cout<< s<< endl; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CodeForces/630A.cpp: -------------------------------------------------------------------------------- 1 | // Again Twenty Five! 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | cout<< "25"<< endl; 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /CodeForces/703A.py: -------------------------------------------------------------------------------- 1 | # Mishka and Game 2 | 3 | import sys 4 | 5 | input = list(map(int, sys.stdin.read().strip().split())) 6 | 7 | n = input[0] 8 | 9 | mishka, chris = 0, 0 10 | for i in range(1, n * 2, 2): 11 | if input[i] > input[i + 1]: 12 | mishka += 1 13 | if input[i] < input[i + 1]: 14 | chris += 1 15 | 16 | if mishka > chris: 17 | sys.stdout.write('Mishka\n') 18 | elif mishka < chris: 19 | sys.stdout.write('Chris\n') 20 | else: 21 | sys.stdout.write('Friendship is magic!^^\n') 22 | -------------------------------------------------------------------------------- /CodeForces/705A.cpp: -------------------------------------------------------------------------------- 1 | // Hulk 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | #define vi vector 13 | #define pii pair 14 | #define vii vector 15 | #define rep(i,a,b) for(int i=a; i=b; i--) 17 | #define for_each(x,y) for(auto &x : y) 18 | #define pb push_back 19 | #define ff first 20 | #define ss second 21 | 22 | int main() 23 | { 24 | int n; cin>> n; 25 | 26 | string ans = ""; 27 | for(int i=1; i<=n; i++) { 28 | if(i%2 != 0) ans+="I hate"; 29 | else ans+="I love"; 30 | 31 | if(i != n) ans+=" that "; 32 | else ans+=" it"; 33 | } 34 | cout<< ans<< endl; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /CodeForces/723A.cpp: -------------------------------------------------------------------------------- 1 | // The New Year: Meeting Friends 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int minimumTotalDistance(vector positions) { 9 | sort(positions.begin(), positions.end()); 10 | int median = positions[1]; 11 | int totalDistance = abs(positions[0] - median) + abs(positions[2] - median); 12 | 13 | return totalDistance; 14 | } 15 | 16 | 17 | int main() { 18 | vector positions(3); 19 | int num; 20 | for (int i=0; i<3; i++) { 21 | cin>> positions[i]; 22 | } 23 | int result = minimumTotalDistance(positions); 24 | cout<< result<< endl; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /CodeForces/734A.cpp: -------------------------------------------------------------------------------- 1 | // Anton and Danik 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | #define vi vector 13 | #define pii pair 14 | #define vii vector 15 | #define rep(i,a,b) for(int i=a; i=b; i--) 17 | #define for_each(x,y) for(auto &x : y) 18 | #define pb push_back 19 | #define ff first 20 | #define ss second 21 | 22 | int main() 23 | { 24 | int n; cin>> n; 25 | string s; cin>> s; 26 | 27 | int A=0, D=0; 28 | for_each(ch, s) { 29 | if(ch == 'A') A++; 30 | else D++; 31 | } 32 | 33 | if(A > D) { 34 | cout<< "Anton"<< endl; 35 | } else if(D > A) { 36 | cout<< "Danik"<< endl; 37 | } else { 38 | cout<< "Friendship"<< endl; 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /CodeForces/758A.py: -------------------------------------------------------------------------------- 1 | # Holiday Of Equality 2 | 3 | import sys 4 | 5 | n = int(sys.stdin.readline().strip()) 6 | welfare = list(map(int, sys.stdin.readline().strip().split())) 7 | 8 | min_charges, max_welfare = 0, max(welfare) 9 | for i in welfare: 10 | min_charges += max_welfare - i 11 | 12 | sys.stdout.write('{}'.format(min_charges)) 13 | -------------------------------------------------------------------------------- /CodeForces/791A.cpp: -------------------------------------------------------------------------------- 1 | // Bear and Big Brother 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a, b; 9 | cin >> a >> b; 10 | 11 | int ans = 0; 12 | while (a <= b) { 13 | a = a * 3; 14 | b = b * 2; 15 | ans++; 16 | } 17 | cout << ans << endl; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /CodeForces/996A.cpp: -------------------------------------------------------------------------------- 1 | // Hit the Lottery 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | #define ll long long 21 | 22 | int main() 23 | { 24 | ll n; cin>> n; 25 | 26 | vi denominators; 27 | denominators.pb(100); 28 | denominators.pb(20); 29 | denominators.pb(10); 30 | denominators.pb(5); 31 | denominators.pb(1); 32 | 33 | int ans = 0; 34 | for_each(denominator, denominators) { 35 | while(n >= denominator) { 36 | n -= denominator; 37 | ans++; 38 | } 39 | } 40 | cout<< ans<< endl; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /CodeForces/contests/2036/A.cpp: -------------------------------------------------------------------------------- 1 | // A. Quintomania 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define vi vector 12 | #define pii pair 13 | #define vii vector 14 | #define rep(i,a,b) for(int i=a; i=b; i--) 16 | #define for_each(x,y) for(auto &x : y) 17 | #define pb push_back 18 | #define ff first 19 | #define ss second 20 | 21 | int main() 22 | { 23 | int t; cin >> t; 24 | while (t--) 25 | { 26 | int n; cin >> n; 27 | vi notes(n); 28 | rep(i, 0, n) 29 | { 30 | cin >> notes[i]; 31 | } 32 | 33 | string result = "YES"; 34 | rep(i, 1, n) 35 | { 36 | int interval = abs(notes[i] - notes[i - 1]); 37 | if(interval != 5 && interval != 7) { 38 | result = "NO"; 39 | break; 40 | } 41 | } 42 | cout<< result<< endl; 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /HackerRank/Python/arithmetic_operators.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | b = int(input()) 4 | 5 | print(a + b, a - b, a * b, sep='\n') 6 | -------------------------------------------------------------------------------- /HackerRank/Python/division.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | b = int(input()) 4 | 5 | print(a // b, a / b, sep='\n') 6 | -------------------------------------------------------------------------------- /HackerRank/Python/find_runner_up_score.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | arr = map(int, input().split()) 4 | 5 | scores = list(arr) 6 | max_score = max(scores[0], scores[1]) 7 | second_max_score = min(scores[0], scores[1]) 8 | 9 | for i in range(2, n): 10 | if scores[i] > max_score: 11 | second_max_score = max_score 12 | max_score = scores[i] 13 | elif second_max_score < scores[i] != max_score: 14 | second_max_score = scores[i] 15 | elif max_score == second_max_score and second_max_score != scores[i]: 16 | second_max_score = scores[i] 17 | 18 | print(second_max_score) 19 | -------------------------------------------------------------------------------- /HackerRank/Python/if_else.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | if __name__ == '__main__': 10 | n = int(input().strip()) 11 | 12 | if n % 2 != 0: 13 | sys.stdout.write('Weird\n') 14 | else: 15 | if 2 <= n <= 5: 16 | sys.stdout.write('Not Weird\n') 17 | elif 6 <= n <= 20: 18 | sys.stdout.write('Weird\n') 19 | else: 20 | sys.stdout.write('Not Weird\n') 21 | -------------------------------------------------------------------------------- /HackerRank/Python/loops.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | 4 | for i in range(n): 5 | print(i * i) 6 | -------------------------------------------------------------------------------- /HackerRank/Python/print_function.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | 4 | for i in range(1, n + 1): 5 | print(i, end='') 6 | -------------------------------------------------------------------------------- /HackerRank/Python/say_hello_world.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if __name__ == '__main__': 4 | sys.stdout.write('Hello, World!') 5 | -------------------------------------------------------------------------------- /HackerRank/Python/write_a_function.py: -------------------------------------------------------------------------------- 1 | def is_leap(year): 2 | leap = False 3 | 4 | if ((year % 4 == 0 and year % 100 != 0) or 5 | (year % 400 == 0 and year % 100 == 0)): 6 | leap = True 7 | 8 | return leap 9 | 10 | 11 | year = int(input()) 12 | print(is_leap(year)) 13 | -------------------------------------------------------------------------------- /HackerRank/compare_the_triplets.py: -------------------------------------------------------------------------------- 1 | # The function is expected to return an INTEGER_ARRAY. 2 | # The function accepts following parameters: 3 | # 1. INTEGER_ARRAY a 4 | # 2. INTEGER_ARRAY b 5 | # 6 | 7 | def compareTriplets(a, b): 8 | ans = [0, 0] 9 | for i in range(0, len(a)): 10 | if(a[i]>b[i]): 11 | ans[0] = ans[0] + 1 12 | if(a[i] 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | // class Solution { 9 | // public: 10 | // vector twoSum(vector& nums, int target) { 11 | // for(int i=0; i{i, j}; 15 | // } 16 | // } 17 | // } 18 | // return vector{}; 19 | // } 20 | // }; 21 | 22 | // using hashmap 23 | class Solution { 24 | public: 25 | vector twoSum(vector& nums, int target) { 26 | 27 | unordered_map num_map; 28 | for(int i=0; i nums = {2,7,11,15}; 44 | vector nums = {3,2,4}; 45 | vector ans = s.twoSum(nums, 6); 46 | for(int i=0; i List[int]: 7 | hashmap = {} 8 | for i, num in enumerate(nums): 9 | complement = target - num 10 | if complement in hashmap: 11 | return [hashmap[complement], i] 12 | hashmap[num] = i 13 | return [] 14 | 15 | 16 | s = Solution() 17 | print(s.twoSum([2, 7, 11, 15], 9)) 18 | print(s.twoSum([3, 2, 4], 6)) 19 | print(s.twoSum([3, 3], 6)) 20 | -------------------------------------------------------------------------------- /LeetCode/12.py: -------------------------------------------------------------------------------- 1 | # Integer to Roman 2 | 3 | class Solution: 4 | def intToRoman(self, num: int) -> str: 5 | sym_val = {1: "I", 5: "V", 10: "X", 50: "L", 100: "C", 500: "D", 1000: "M", 6 | 4: "IV", 9: "IX", 40: "XL", 90: "XC", 400: "CD", 900: "CM"} 7 | values = [1, 4, 5, 9, 10, 40, 50, 90, 8 | 100, 400, 500, 900, 1000] 9 | sym = ["I", "IV", "V", "IX", "X", "XL", 10 | "L", "XC", "C", "CD", "D", "CM", "M"] 11 | 12 | roman = '' 13 | i = 12 14 | while num > 0: 15 | div = num // values[i] 16 | num = num % values[i] 17 | 18 | while div: 19 | roman += sym[i] 20 | div -= 1 21 | i -= 1 22 | return roman 23 | 24 | 25 | if __name__ == "__main__": 26 | s = Solution() 27 | 28 | number = 3749 29 | print("Roman value is:", end=" ") 30 | print(s.intToRoman(number)) 31 | -------------------------------------------------------------------------------- /LeetCode/125.py: -------------------------------------------------------------------------------- 1 | # Valid Palindrome 2 | 3 | class Solution: 4 | def isPalindrome(self, s: str) -> bool: 5 | # s = ''.join(char.lower() for char in s if char.isalnum()) 6 | s = ''.join(filter(str.isalnum, s)) 7 | s = s.lower() 8 | return s == s[::-1] 9 | 10 | 11 | soln = Solution() 12 | print(soln.isPalindrome("A man, a plan, a canal: Panama")) 13 | print(soln.isPalindrome("race a car")) 14 | print(soln.isPalindrome(" ")) 15 | -------------------------------------------------------------------------------- /LeetCode/14.py: -------------------------------------------------------------------------------- 1 | # Longest Common Prefix 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def longestCommonPrefix(self, strs: List[str]) -> str: 8 | # strs = sorted(strs) 9 | # ans = '' 10 | # for i in range(len(strs[0])): 11 | # if strs[0][i] == strs[-1][i]: 12 | # ans += strs[0][i] 13 | # else: 14 | # break 15 | # return ans 16 | 17 | mini, maxi = min(strs), max(strs) 18 | 19 | for i in range(len(mini)): 20 | if mini[i] != maxi[i]: 21 | return mini[:i] 22 | return mini 23 | 24 | 25 | if __name__ == '__main__': 26 | s = Solution() 27 | print(s.longestCommonPrefix(["flower", "flow", "flight"])) 28 | print(s.longestCommonPrefix(["dog", "racecar", "car"])) 29 | -------------------------------------------------------------------------------- /LeetCode/1470.py: -------------------------------------------------------------------------------- 1 | # Shuffle the Array 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def shuffle(self, nums: List[int], n: int) -> List[int]: 7 | shuffled_list = [] 8 | for i in range(n): 9 | shuffled_list.append(nums[i]) 10 | shuffled_list.append(nums[i + n]) 11 | 12 | return shuffled_list 13 | 14 | 15 | if __name__ == '__main__': 16 | s = Solution() 17 | print(s.shuffle([2, 5, 1, 3, 4, 7], 3)) 18 | print(s.shuffle([1, 2, 3, 4, 4, 3, 2, 1], 4)) 19 | print(s.shuffle([1, 1, 2, 2], 2)) 20 | -------------------------------------------------------------------------------- /LeetCode/168.py: -------------------------------------------------------------------------------- 1 | # Excel Sheet Column Title 2 | 3 | 4 | class Solution: 5 | def convertToTitle(self, columnNumber: int) -> str: 6 | title = "" 7 | while columnNumber > 0: 8 | columnNumber -= 1 9 | remainder = columnNumber % 26 10 | title = chr(ord("A") + remainder) + title 11 | columnNumber //= 26 12 | return title 13 | 14 | 15 | def main(): 16 | s = Solution() 17 | print(s.convertToTitle(1)) 18 | print(s.convertToTitle(28)) 19 | print(s.convertToTitle(79)) 20 | print(s.convertToTitle(2147483647)) 21 | 22 | 23 | if __name__ == "__main__": 24 | main() 25 | -------------------------------------------------------------------------------- /LeetCode/169.py: -------------------------------------------------------------------------------- 1 | # Majority Element 2 | from typing import List 3 | from collections import defaultdict 4 | 5 | 6 | class Solution: 7 | def majorityElement(self, nums: List[int]) -> int: 8 | # using nested loops 9 | # n = len(nums) 10 | # for i in range(n): 11 | # count = 0 12 | # for j in range(n): 13 | # if nums[i] == nums[j]: 14 | # count += 1 15 | # if count >= n // 2: 16 | # return nums[i] 17 | # return -1 18 | 19 | # using hashmap 20 | n = len(nums) 21 | count_map = defaultdict(int) 22 | for num in nums: 23 | count_map[num] += 1 24 | 25 | if count_map[num] > n / 2: 26 | return num 27 | return -1 28 | 29 | 30 | if __name__ == '__main__': 31 | s = Solution() 32 | print(s.majorityElement([2, 2, 1, 1, 1, 2, 2])) 33 | -------------------------------------------------------------------------------- /LeetCode/17.py: -------------------------------------------------------------------------------- 1 | # Letter Combinations of a Phone Number 2 | 3 | from typing import List 4 | import itertools 5 | 6 | class Solution: 7 | def letterCombinations(self, digits: str) -> List[str]: 8 | mapping = {2: 'abc', 3: 'def', 4: 'ghi', 5: 'jkl', 9 | 6: 'mno', 7: 'pqrs', 8: 'tuv', 9: 'wxyz'} 10 | 11 | if not digits: 12 | return [] 13 | 14 | strings = [mapping[int(digit)] for digit in digits if int(digit) in mapping] 15 | 16 | combinations = itertools.product(*strings) 17 | return [''.join(combination) for combination in combinations] 18 | 19 | 20 | if __name__ == '__main__': 21 | solution = Solution() 22 | print(solution.letterCombinations('23')) 23 | print(solution.letterCombinations('')) 24 | print(solution.letterCombinations('2')) -------------------------------------------------------------------------------- /LeetCode/171.py: -------------------------------------------------------------------------------- 1 | # Excel Sheet Column Number 2 | 3 | 4 | class Solution: 5 | def titleToNumber(self, columnTitle: str) -> int: 6 | col_num = 0 7 | for i in range(len(columnTitle)): 8 | col_num += pow(26, len(columnTitle) - 1 - i) * ( 9 | ord(columnTitle[i]) - ord("A") + 1 10 | ) 11 | return col_num 12 | 13 | 14 | def main(): 15 | s = Solution() 16 | print(s.titleToNumber("A")) 17 | print(s.titleToNumber("AB")) 18 | print(s.titleToNumber("ZY")) 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /LeetCode/1732find_the_highest_altitude.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestAltitude(self, gain): 3 | max = 0 4 | a = 0 5 | 6 | for i in gain: 7 | a+=i 8 | if a > max: 9 | max = a 10 | return max 11 | 12 | 13 | s = Solution() 14 | 15 | nums = [-5, 1, 5, 0, -7] 16 | 17 | print(s.largestAltitude(nums)) 18 | -------------------------------------------------------------------------------- /LeetCode/2.py: -------------------------------------------------------------------------------- 1 | # Add Two Numbers 2 | 3 | from typing import Optional 4 | 5 | 6 | # Definition for singly-linked list. 7 | class ListNode: 8 | def __init__(self, val=0, next=None): 9 | self.val = val 10 | self.next = next 11 | 12 | 13 | class Solution: 14 | def get_reverse_num(self, head: ListNode): 15 | reverse_num = '' 16 | curr = head 17 | 18 | while curr is not None: 19 | reverse_num += str(curr.val) 20 | curr = curr.next 21 | 22 | return int(reverse_num[::-1]) 23 | 24 | def make_list(self, num1: int, num2: int) -> ListNode: 25 | reversed_sum = str(num1 + num2)[::-1] 26 | head = ListNode(val=int(reversed_sum[0]), next=None) 27 | curr = head 28 | for digit in reversed_sum[1:]: 29 | new_node = ListNode(val=int(digit), next=None) 30 | curr.next = new_node 31 | curr = new_node 32 | 33 | return head 34 | 35 | def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: 36 | num1, num2 = self.get_reverse_num(l1), self.get_reverse_num(l2) 37 | return self.make_list(num1, num2) 38 | -------------------------------------------------------------------------------- /LeetCode/206.py: -------------------------------------------------------------------------------- 1 | # Reverse Linked List 2 | 3 | from typing import Optional 4 | 5 | 6 | # Definition for singly-linked list. 7 | class ListNode: 8 | def __init__(self, val=0, next=None): 9 | self.val = val 10 | self.next = next 11 | 12 | 13 | class Solution: 14 | def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: 15 | curr = head 16 | prev = None 17 | 18 | while curr is not None: 19 | next_node = curr.next 20 | curr.next = prev 21 | prev = curr 22 | curr = next_node 23 | 24 | return prev 25 | 26 | def print_list(self, node: ListNode): 27 | while node is not None: 28 | print(f'{node.val}', end="->") 29 | node = node.next 30 | print('None') 31 | 32 | 33 | if __name__ == '__main__': 34 | head = ListNode(val=10) 35 | node2 = ListNode(val=20) 36 | node3 = ListNode(val=30) 37 | node4 = ListNode(val=40) 38 | node5 = ListNode(val=50) 39 | 40 | head.next = node2 41 | node2.next = node3 42 | node3.next = node4 43 | node4.next = node5 44 | 45 | s = Solution() 46 | 47 | s.print_list(head) 48 | reversed_list = s.reverseList(head) 49 | s.print_list(reversed_list) 50 | -------------------------------------------------------------------------------- /LeetCode/21.py: -------------------------------------------------------------------------------- 1 | # Merge Two Sorted Lists 2 | from typing import Optional 3 | 4 | 5 | class ListNode: 6 | def __init__(self, val=0, next=None): 7 | self.val = val 8 | self.next = next 9 | 10 | 11 | class Solution: 12 | def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: 13 | # head_node = ListNode() 14 | # current_node = head_node 15 | # 16 | # while list1 is not None and list2 is not None: 17 | # if list1.val <= list2.val: 18 | # current_node.next = list1 19 | # list1 = list1.next 20 | # else: 21 | # current_node.next = list2 22 | # list2 = list2.next 23 | # 24 | # current_node = current_node.next 25 | # 26 | # if list1 is not None: 27 | # current_node.next = list1 28 | # else: 29 | # current_node.next = list2 30 | # 31 | # return head_node.next 32 | 33 | if list1 is None: 34 | return list2 35 | elif list2 is None: 36 | return list1 37 | elif list1 is None and list2 is None: 38 | return None 39 | elif list1.val <= list2.val: 40 | list1.next = self.mergeTwoLists(list1.next, list2) 41 | return list1 42 | else: 43 | list2.next = self.mergeTwoLists(list1, list2.next) 44 | return list2 45 | -------------------------------------------------------------------------------- /LeetCode/225.py: -------------------------------------------------------------------------------- 1 | # Implement Stack using Queues 2 | 3 | class MyStack: 4 | 5 | def __init__(self): 6 | self.stack = [] 7 | 8 | def push(self, x: int) -> None: 9 | self.stack.insert(0, x) 10 | 11 | def pop(self) -> int: 12 | return self.stack.pop(0) 13 | 14 | def top(self) -> int: 15 | return self.stack[0] 16 | 17 | def empty(self) -> bool: 18 | if len(self.stack) == 0: 19 | return True 20 | return False 21 | -------------------------------------------------------------------------------- /LeetCode/231.py: -------------------------------------------------------------------------------- 1 | # Power of Two 2 | 3 | class Solution: 4 | def isPowerOfTwo(self, n: int) -> bool: 5 | # count = 1 6 | # while count <= n: 7 | # if count == n: 8 | # return True 9 | # count *= 2 10 | # return False 11 | 12 | if n <= 0: 13 | return False 14 | 15 | while n % 2 == 0: 16 | n //= 2 17 | 18 | return n == 1 19 | 20 | 21 | if __name__ == '__main__': 22 | s = Solution() 23 | print(s.isPowerOfTwo(3)) 24 | -------------------------------------------------------------------------------- /LeetCode/238product_of_array_except_self.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def productExceptSelf(self, nums: List[int]) -> List[int]: 3 | n = len(nums) 4 | 5 | prefix_product = [1] * n 6 | suffix_product = [1] * n 7 | 8 | for i in range(1, n): 9 | prefix_product[i] = prefix_product[i-1] * nums[i-1] 10 | 11 | for i in range(n-2, -1, -1): 12 | suffix_product[i] = suffix_product[i+1] * nums[i+1] 13 | 14 | return [prefix_product[i] * suffix_product[i] for i in range(n)] -------------------------------------------------------------------------------- /LeetCode/26.py: -------------------------------------------------------------------------------- 1 | # Remove Duplicates from Sorted Array 2 | from typing import List, Iterable, Union 3 | 4 | 5 | class Solution: 6 | def removeDuplicates(self, nums: List[int]) -> int: 7 | j = 1 8 | for i in range(1, len(nums)): 9 | if nums[i] != nums[i - 1]: 10 | nums[j] = nums[i] 11 | j += 1 12 | 13 | return j 14 | 15 | 16 | s = Solution() 17 | print(s.removeDuplicates([1, 1, 2])) 18 | print(s.removeDuplicates([0, 0, 1, 1, 1, 2, 2, 3, 3, 4])) 19 | -------------------------------------------------------------------------------- /LeetCode/27RemoveElement.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int removeElement(vector& nums, int val) { 9 | nums.erase(remove(nums.begin(), nums.end(), val), nums.end()); 10 | 11 | return nums.size(); 12 | } 13 | }; -------------------------------------------------------------------------------- /LeetCode/326.py: -------------------------------------------------------------------------------- 1 | # Power of Three 2 | import math 3 | 4 | 5 | class Solution: 6 | def isPowerOfThree(self, n: int) -> bool: 7 | if n <= 0: 8 | return False 9 | 10 | # wrong ans for n=243 11 | # base = 3 12 | # p = math.log(n) / math.log(base) 13 | # return p.is_integer() 14 | 15 | while n % 3 == 0: 16 | n //= 3 17 | return n == 1 18 | 19 | 20 | if __name__ == '__main__': 21 | s = Solution() 22 | print(s.isPowerOfThree(27)) 23 | print(s.isPowerOfThree(0)) 24 | print(s.isPowerOfThree(-1)) 25 | print(s.isPowerOfThree(243)) 26 | -------------------------------------------------------------------------------- /LeetCode/342.py: -------------------------------------------------------------------------------- 1 | # Power of Four 2 | 3 | class Solution: 4 | def isPowerOfFour(self, n: int) -> bool: 5 | if n <= 0: 6 | return False 7 | 8 | while n % 4 == 0: 9 | n //= 4 10 | return n == 1 11 | 12 | 13 | if __name__ == '__main__': 14 | s = Solution() 15 | print(s.isPowerOfFour(16)) 16 | print(s.isPowerOfFour(5)) 17 | print(s.isPowerOfFour(1)) 18 | -------------------------------------------------------------------------------- /LeetCode/344.py: -------------------------------------------------------------------------------- 1 | # Reverse String 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def reverseString(self, s: List[str]) -> None: 8 | """ 9 | Do not return anything, modify s in-place instead. 10 | """ 11 | for i in range(len(s) // 2): 12 | s[i], s[-i - 1] = s[-i - 1], s[i] 13 | 14 | print(s) 15 | 16 | 17 | if __name__ == '__main__': 18 | s = Solution() 19 | s.reverseString(["h", "e", "l", "l", "o"]) 20 | s.reverseString(["H", "a", "n", "n", "a", "h"]) 21 | -------------------------------------------------------------------------------- /LeetCode/345.py: -------------------------------------------------------------------------------- 1 | # Reverse Vowels of a String 2 | 3 | 4 | class Solution: 5 | def reverseVowels(self, s: str) -> str: 6 | vowels = set("aeiouAEIOU") 7 | s = list(s) 8 | 9 | l, r = 0, len(s) - 1 10 | while l < r: 11 | if s[l] not in vowels: 12 | l += 1 13 | elif s[r] not in vowels: 14 | r -= 1 15 | else: 16 | s[l], s[r] = s[r], s[l] 17 | l += 1 18 | r -= 1 19 | 20 | return "".join(s) 21 | 22 | 23 | def main(): 24 | s = Solution() 25 | print(s.reverseVowels("IceCreAm")) 26 | print(s.reverseVowels("leetcode")) 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /LeetCode/35.py: -------------------------------------------------------------------------------- 1 | # Search Insert Position 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def searchInsert(self, nums: List[int], target: int) -> int: 7 | left, right = 0, len(nums) - 1 8 | 9 | while left <= right: 10 | mid = left + (right - left) // 2 11 | if nums[mid] > target: 12 | right = mid - 1 13 | elif nums[mid] < target: 14 | left = mid + 1 15 | else: 16 | return mid 17 | return left 18 | 19 | 20 | if __name__ == '__main__': 21 | s = Solution() 22 | print(s.searchInsert([1, 3, 5, 6], 5)) 23 | print(s.searchInsert([1, 3, 5, 6], 2)) 24 | print(s.searchInsert([1, 3, 5, 6], 7)) 25 | print(s.searchInsert([1, 3, 5, 6], 0)) 26 | print(s.searchInsert([1, 3], 2)) 27 | -------------------------------------------------------------------------------- /LeetCode/3512.py: -------------------------------------------------------------------------------- 1 | # Minimum Operations to Make Array Sum Divisible by K 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def minOperations(self, nums: List[int], k: int) -> int: 8 | return sum(nums) % k 9 | 10 | 11 | def main(): 12 | s = Solution() 13 | print(s.minOperations([3, 9, 7], 5)) 14 | print(s.minOperations([4, 1, 3], 4)) 15 | 16 | 17 | if __name__ == "__main__": 18 | main() 19 | -------------------------------------------------------------------------------- /LeetCode/383.py: -------------------------------------------------------------------------------- 1 | # Ransom Note 2 | 3 | 4 | class Solution: 5 | def canConstruct(self, ransomNote: str, magazine: str) -> bool: 6 | ## 1st solution ## 7 | 8 | # freq_map_magazine = {} 9 | # for char in magazine: 10 | # freq_map_magazine[char] = freq_map_magazine.get(char, 0) + 1 11 | # 12 | # for char in ransomNote: 13 | # if char not in freq_map_magazine: 14 | # return False 15 | # if not freq_map_magazine[char] > 0: 16 | # return False 17 | # freq_map_magazine[char] -= 1 18 | # return True 19 | 20 | ## 2nd solution ## 21 | 22 | for element in ransomNote: 23 | if element in magazine: 24 | magazine = magazine.replace(element, " ", 1) 25 | else: 26 | return False 27 | return True 28 | 29 | 30 | def main(): 31 | s = Solution() 32 | print(s.canConstruct("a", "b")) 33 | print(s.canConstruct("aa", "ab")) 34 | print(s.canConstruct("aa", "aab")) 35 | 36 | 37 | if __name__ == "__main__": 38 | main() 39 | -------------------------------------------------------------------------------- /LeetCode/392.py: -------------------------------------------------------------------------------- 1 | # Is Subsequence 2 | 3 | 4 | class Solution: 5 | def isSubsequence(self, s: str, t: str) -> bool: 6 | # i, j = 0, 0 7 | # while i < len(s) and j < len(t): 8 | # if s[i] == t[j]: 9 | # i += 1 10 | # j += 1 11 | # else: 12 | # t = t.replace(t[j], " ", 1) 13 | # j += 1 14 | # t = t.replace(" ", "") 15 | # return s == t 16 | 17 | i, j = 0, 0 18 | while i < len(s) and j < len(t): 19 | if s[i] == t[j]: 20 | i += 1 21 | j += 1 22 | return i == len(s) 23 | 24 | 25 | def main(): 26 | s = Solution() 27 | print(s.isSubsequence("abc", "ahbgdc")) 28 | print(s.isSubsequence("axc", "ahbgdc")) 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /LeetCode/409.py: -------------------------------------------------------------------------------- 1 | # Longest Palindrome 2 | 3 | 4 | class Solution: 5 | def longestPalindrome(self, s: str) -> int: 6 | freq_map = {} 7 | for char in s: 8 | freq_map[char] = freq_map.get(char, 0) + 1 9 | 10 | res = 0 11 | has_odd_frq = False 12 | for freq in freq_map.values(): 13 | if freq % 2 == 0: 14 | res += freq 15 | else: 16 | res += freq - 1 17 | has_odd_frq = True 18 | 19 | if has_odd_frq: 20 | return res + 1 21 | return res 22 | 23 | 24 | def main(): 25 | s = Solution() 26 | print(s.longestPalindrome("abccccdd")) 27 | print(s.longestPalindrome("s")) 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /LeetCode/412.py: -------------------------------------------------------------------------------- 1 | # Fizz Buzz 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def fizzBuzz(self, n: int) -> List[str]: 8 | res = [] 9 | 10 | for i in range(1, n + 1): 11 | if i % 3 == 0 and i % 5 == 0: 12 | res.append("FizzBuzz") 13 | elif i % 3 == 0: 14 | res.append("Fizz") 15 | elif i % 5 == 0: 16 | res.append("Buzz") 17 | else: 18 | res.append(str(i)) 19 | 20 | return res 21 | 22 | 23 | def main(): 24 | s = Solution() 25 | print(s.fizzBuzz(3)) 26 | print(s.fizzBuzz(5)) 27 | print(s.fizzBuzz(15)) 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /LeetCode/415.py: -------------------------------------------------------------------------------- 1 | # Add Strings 2 | 3 | class Solution: 4 | def addStrings(self, num1: str, num2: str) -> str: 5 | num1, num2 = num1[::-1], num2[::-1] 6 | 7 | result, carry = '', 0 8 | for i in range(max(len(num1), len(num2))): 9 | digit1 = int(num1[i]) if i < len(num1) else 0 10 | digit2 = int(num2[i]) if i < len(num2) else 0 11 | 12 | total = digit1 + digit2 + carry 13 | carry = total // 10 14 | result += str(total % 10) 15 | 16 | if carry: 17 | result += str(carry) 18 | 19 | return result[::-1] 20 | 21 | 22 | if __name__ == '__main__': 23 | s = Solution() 24 | print(s.addStrings('11', '123')) 25 | print(s.addStrings('456', '77')) 26 | print(s.addStrings('0', '0')) 27 | -------------------------------------------------------------------------------- /LeetCode/441.py: -------------------------------------------------------------------------------- 1 | # Arranging Coins 2 | 3 | class Solution: 4 | def arrangeCoins(self, n: int) -> int: 5 | complete_rows = 1 6 | while n >= complete_rows: 7 | n -= complete_rows 8 | complete_rows += 1 9 | return complete_rows - 1 10 | 11 | 12 | if __name__ == "__main__": 13 | s = Solution() 14 | print(s.arrangeCoins(5)) 15 | print(s.arrangeCoins(8)) -------------------------------------------------------------------------------- /LeetCode/442_find_all_duplicates.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicates(self, nums): 3 | ans = [] 4 | nums.sort() 5 | for i in range(len(nums)-1): 6 | if nums[i] == nums[i+1] and nums[i] not in ans: 7 | ans.append(nums[i]) 8 | 9 | return ans 10 | 11 | nums = [4,3,2,7,8,2,3,1] 12 | 13 | solution = Solution() 14 | solution.findDuplicates(nums) -------------------------------------------------------------------------------- /LeetCode/445.py: -------------------------------------------------------------------------------- 1 | # Add Two Numbers II 2 | 3 | from typing import Optional 4 | 5 | 6 | # Definition for singly-linked list. 7 | class ListNode: 8 | def __init__(self, val=0, next=None): 9 | self.val = val 10 | self.next = next 11 | 12 | 13 | class Solution: 14 | def get_num(self, head: ListNode) -> int: 15 | num = '' 16 | curr = head 17 | 18 | while curr is not None: 19 | num += str(curr.val) 20 | curr = curr.next 21 | return int(num) 22 | 23 | def make_list(self, num: int) -> ListNode: 24 | num = str(num) 25 | head = ListNode(val=int(num[0])) 26 | curr = head 27 | for digit in num[1:]: 28 | new_node = ListNode(val=int(digit)) 29 | curr.next = new_node 30 | curr = new_node 31 | 32 | return head 33 | 34 | def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: 35 | num1, num2 = self.get_num(l1), self.get_num(l2) 36 | sum = num1 + num2 37 | 38 | return self.make_list(sum) 39 | -------------------------------------------------------------------------------- /LeetCode/448.py: -------------------------------------------------------------------------------- 1 | # Find All Numbers Disappeared in an Array 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def findDisappearedNumbers(self, nums: List[int]) -> List[int]: 8 | return list(set(range(1, len(nums) + 1)) - set(nums)) 9 | 10 | # using hash 11 | # result = [] 12 | # hashset = set(nums) 13 | # for i in range(1, len(nums) + 1): 14 | # if i not in hashset: 15 | # result.append(i) 16 | # return result 17 | 18 | # without extra space 19 | # for i in range(len(nums)): 20 | # index = abs(nums[i]) - 1 21 | # if nums[index] > 0: 22 | # nums[index] = -nums[index] 23 | # 24 | # result = [] 25 | # for i in range(len(nums)): 26 | # if nums[i] > 0: 27 | # result.append(i + 1) 28 | # 29 | # return result 30 | 31 | 32 | if __name__ == '__main__': 33 | s = Solution() 34 | print(s.findDisappearedNumbers([4, 3, 2, 7, 8, 2, 3, 1])) 35 | print(s.findDisappearedNumbers([1, 1])) 36 | -------------------------------------------------------------------------------- /LeetCode/5.py: -------------------------------------------------------------------------------- 1 | # Longest Palindromic Substring 2 | 3 | class Solution: 4 | def check_pal(self, s, low, high) -> bool: 5 | while low < high: 6 | if s[low] != s[high]: 7 | return False 8 | low += 1 9 | high -= 1 10 | return True 11 | 12 | def longestPalindrome(self, s: str) -> str: 13 | n = len(s) 14 | 15 | max_len = 1 16 | start = 0 17 | 18 | for i in range(n): 19 | for j in range(i, n): 20 | if self.check_pal(s, i, j) and (j - i + 1) > max_len: 21 | start = i 22 | max_len = j - i + 1 23 | return s[start:start + max_len] 24 | -------------------------------------------------------------------------------- /LeetCode/500.py: -------------------------------------------------------------------------------- 1 | # Keyboard Row 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def findWords(self, words: List[str]) -> List[str]: 8 | # row1, row2, row3 = "qwertyuiop", "asdfghjkl", "zxcvbnm" 9 | # res = [] 10 | # 11 | # for i in range(len(words)): 12 | # word = words[i].lower() 13 | # row = None 14 | # flag = True 15 | # if word[0] in row1: 16 | # row = row1 17 | # elif word[0] in row2: 18 | # row = row2 19 | # else: 20 | # row = row3 21 | # 22 | # for j in range(1, len(word)): 23 | # if word[j] not in row: 24 | # flag = False 25 | # break 26 | # 27 | # if flag: 28 | # res.append(words[i]) 29 | # 30 | # return res 31 | 32 | rows = [set("qwertyuiop"), set("asdfghjkl"), set("zxcvbnm")] 33 | 34 | def is_one_row(word: str) -> bool: 35 | for row in rows: 36 | if word[0].lower() in row: 37 | return all(c.lower() in row for c in word) 38 | return False 39 | 40 | return [word for word in words if is_one_row(word)] 41 | 42 | 43 | def main(): 44 | s = Solution() 45 | print(s.findWords(["Hello", "Alaska", "Dad", "Peace"])) 46 | print(s.findWords(["omk"])) 47 | print(s.findWords(["adsdf", "sfd"])) 48 | 49 | 50 | if __name__ == "__main__": 51 | main() 52 | -------------------------------------------------------------------------------- /LeetCode/7.py: -------------------------------------------------------------------------------- 1 | # Reverse Integer 2 | 3 | class Solution: 4 | def reverse(self, x: int) -> int: 5 | max_int32 = 2 ** 31 - 1 6 | output = 0 7 | sign = 1 if x >= 0 else -1 8 | x = abs(x) 9 | while x > 0: 10 | digit = x % 10 11 | x = x // 10 12 | output = output * 10 + digit 13 | if output > max_int32: 14 | return 0 15 | 16 | return output * sign 17 | -------------------------------------------------------------------------------- /LeetCode/82.py: -------------------------------------------------------------------------------- 1 | # Remove Duplicates from Sorted List II 2 | 3 | from typing import Optional 4 | 5 | 6 | # Definition for singly-linked list. 7 | class ListNode: 8 | def __init__(self, val=0, next=None): 9 | self.val = val 10 | self.next = next 11 | 12 | 13 | class Solution: 14 | def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]: 15 | dummy = ListNode() 16 | dummy.next = head 17 | prev = dummy 18 | curr = head 19 | 20 | while curr: 21 | if curr.next and curr.val == curr.next.val: 22 | while curr.next and curr.val == curr.next.val: 23 | curr = curr.next 24 | prev.next = curr.next 25 | else: 26 | prev = curr 27 | 28 | curr = curr.next 29 | return dummy.next 30 | -------------------------------------------------------------------------------- /LeetCode/83.py: -------------------------------------------------------------------------------- 1 | # Remove Duplicates from Sorted List 2 | 3 | from typing import Optional 4 | 5 | 6 | # Definition for singly-linked list. 7 | class ListNode: 8 | def __init__(self, val=0, next=None): 9 | self.val = val 10 | self.next = next 11 | 12 | 13 | class Solution: 14 | def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]: 15 | # if not head: 16 | # return None 17 | # 18 | # hashset = set() 19 | # hashset.add(head.val) 20 | # curr = head 21 | # 22 | # while curr.next is not None: 23 | # if curr.next.val in hashset: 24 | # curr.next = curr.next.next 25 | # else: 26 | # hashset.add(curr.next.val) 27 | # curr = curr.next 28 | # return head 29 | 30 | curr = head 31 | while curr and curr.next: 32 | if curr.val == curr.next.val: 33 | curr.next = curr.next.next 34 | else: 35 | curr = curr.next 36 | return head 37 | -------------------------------------------------------------------------------- /LeetCode/88.py: -------------------------------------------------------------------------------- 1 | # Merge Sorted Array 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: 7 | """ 8 | Do not return anything, modify nums1 in-place instead. 9 | """ 10 | if n == 0: 11 | return 12 | end_idx = len(nums1) - 1 13 | while n > 0 and m > 0: 14 | if nums2[n - 1] >= nums1[m - 1]: 15 | nums1[end_idx] = nums2[n - 1] 16 | n -= 1 17 | else: 18 | nums1[end_idx] = nums1[m - 1] 19 | m -= 1 20 | end_idx -= 1 21 | while n > 0: 22 | nums1[end_idx] = nums2[n - 1] 23 | n -= 1 24 | end_idx -= 1 25 | 26 | 27 | s = Solution() 28 | print(s.merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3)) 29 | print(s.merge([1], 1, [], 0)) 30 | print(s.merge([0], 0, [1], 1)) 31 | -------------------------------------------------------------------------------- /LeetCode/9PalindromeNumber.py: -------------------------------------------------------------------------------- 1 | # Palindrome Number 2 | 3 | class Solution: 4 | def isPalindrome(self, x: int) -> bool: 5 | s = str(x) 6 | for i in range(0, int(len(s)/2)): 7 | if(s[i] != s[len(s)-i-1]): 8 | return False 9 | return True 10 | 11 | if __name__ == "__main__": 12 | x: int = int(input("Please enter an integer to check palindrome: ")) 13 | print(type(x)) 14 | s = Solution() 15 | print(s.isPalindrome(x)) 16 | -------------------------------------------------------------------------------- /LeetCode/LeetCode75/724find_pivot_index.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | 4 | class Solution: 5 | def pivotIndex(self, nums: List[int]) -> int: 6 | n = len(nums) 7 | 8 | for i in range(n): 9 | left_sum, right_sum = 0, 0 10 | for j in range(0, i): 11 | left_sum += nums[j] 12 | for k in range(i+1, n): 13 | right_sum += nums[k] 14 | 15 | if left_sum == right_sum: 16 | return i 17 | return -1 18 | 19 | 20 | if __name__ == '__main__': 21 | nums = [-322,-985,956,995,-390,265,-36,-879,827,-80,980,207,-798,-866,967,550,142,30,-185,-203,822,340,-94,502,-148,-205,-97,-920,295,-848,708,226,426,-884,170,495,970,587,613,226,-962,140,963,576,-702,-407,303,438,165,51,903,-148,-706,329,-151,800,130,378,-519,45,-2,-735,122,916,853,-606,-118,159,-885,395,-523,211,400,-582,-243,-385,-126,985,315,-152,-555,-566,-825,506,-241,985,-210,955,533,-105,873,-743,297,314,178,506,-118,738,453,-179,-204,-983,552,752,-291,83,-204,-286,598,850,-452,337,261,52,-39,383,265,477,-329,631,120,186,-604,952,-127,156,-777,-940,-703,477,-152,-579,436,391,249,-582,-577,201,-602,-326,793,-438,-523,484,293,-356,-206,651,-669,-901,-548,548,-211,-886,578,-881,441,-650,-702,-906,575,45,878,-975,941,274,585,-421,-733,-841,-865,-613,189,570,152,184,-775,721,184,-963,-242,-473,548,463,552,-118,196,-375,-73,-379,32,945,855,544,-854,874,903,-293,-216,850,-719,-623,545,-57,972,-247,-308,-196,-859,400,-380,-248,130,-42,992,-476,-885,554,-103,705,820,-114,-796,-81,-63,912,-492,771,630,155,470,23,-58,559,-937,-727,-668,1,-338,62,-130,-417,-800,887,-716,320,431,390,-112,471,847,92,-822,200,210,-132,925,-452,486,-348,-567,805,161,-390,-666,155,971,-623,-946,-276,396,89,-244,-23,759,-61,-573,585,958,-993,-987,-429,-503,26,664,-430,822,-201,-822,-470,-72,-725,-259,688,894,-626,821,39,-579,570,444,-14,508,875,336,610,-529,-569,-843,421,-323,661,538,809,-120,916,-580,-36,-518,174,854,-95,282,-268,419,802,219,-274,-862,-784,987,-435,-488,647,-197,-1,512,-137,-288,497,252,685,-716,748,779,677,84,-510,689,90,-37,-47,-727,993,-243,680,-501,830,648,-760,-811,-711,965,-450,-391,-720,989,-60,978,874,-486,95,372,402,941,528,-579,450,-288,40,814,84,-569,-600,-476,-264,-333,395,-767,-864,-245,-271,808,-965,938,321,-716,-486,-779,843,-966,-117,-101,-513,-975,401,155,914,-399,-147,-571,-570,-229,-443,53,-682,79,897,-839,914,-390,410,160,659,-822,177,734,-357,-76,-521,-588,60,958,-864,-697,934,-4,-130,-362,-281,927,228,205,-1,29,-60,805,-187,-495,126,-897,-41,-67,612,393,-7,446,-919,725,-776,-104,462,-489,-815,-378,-28,228,-53,269,107,985,526,283,-659,-897,954,-904,-968,565,-448,-917,-655,-433,364,-227,57,-698,644,891,-938,-306,-772,-106,-864,58,-840,599,-511,533,460,-326,587,965,-771,857,780,-421,-615,133,-742,-901,-693,625,-497,-340,570,-891,-649,-994,-562,743,-950,543,-852,783,-429,-940,395,-562,-665,-194,-245,713,747,-258,-979,337,540,478,-16,-800,-457,-614,698,-454,-879,-867,659,-334,708,-847,105,-242,-16,207,528,224,-105,292,-937,526,917,826,-244,-872,-226,620,306,744,57,767,-974,588,103,340,804,-344,635,329,647,-960,865,682,-403,477,-986,369,535,-710,-301,-155,339,-420,-935,-756,699,-753,117,472,41,-758,-205,-482,-514,321,-206,-389,-715,-926,-667,-257,-914,-828,169,916,700,-791,256,88,-253,-956,-715,313,661,-493,399,510,572,-290,662,575,-264,23,780,637,-581,888,-109,-406,717,-321,826,-557,610,970,-616,42,-303,-611,-900,775,-930,-191,328,-310,622,957,228,76,701,479,190,-258,165,-24,-717,-83,-741,-795,654,282,413,-219,251,62,-577,835,-508,-371,-65,-396,-434,-132,263,198,962,-248,-423,-881,282,598,-499,-877,-554,-673,-552,704,-762,937,591,-210,-777,-48,-485,-768,-490,-46,-667,-657,216,-627,-120,175,66,-386,-367,84,834,-15,369,550,-539,-983,-598,724,-228,-154,422,276,-621,-404,-437,-436,126,-957,839,386,100,688,-164,673,857,-227,-597,-372,-105,867,151,-967,132,-897,-467,941,766,-921,465,-630,821,846,-36,731,-437,-847,-12,166,-513,-380,50,-625,514,829,498,-810,-410,-641,-262,-232,833,-82,-454,-170,600,387,-951,-736,264,-664,-662,-553,14,-815,-802,-254,-890,-379,-273,706,-547,139,901,-568,-126,872,-131,840,408,290,-672,719,1000,-608,972,522,279,-567,932,-95,-911,-310,613,898,-257,-800,-913,979,-326,-396,-313,-924,897,-558,308,802,-723,125,-316,390,-932,184,-53,916,-368,786,680,643,377,-726,695,-569,275,-802,-507,159,-855,70,-336,-570,926,242,838,-48,-790,-261,958,-865,-395,790,593,560,-70,-475,354,585,974,-216,-733,-598,-203,255,0,-534,-864,824,-234,267,-527,-155,578,416,581,749,874,-439,-70,-749,-932,364,883,537,-749,393,-252,-252,-67,324,-110,-201,-608,-147,463,-350,331,-929,-816,-952,-416,869,-595,180,944,50,955,-834,-151,-959,655,369,-992,-982,491,-678,-750,-18,-736,-422,-821,-571,786,381,-94,256,-38,989,966,-777,-36,-968,-289,520,600,-443,253,586,617,445,27,983,472,942,527,604,515,537,-787,234,597,507,717,-115,-805,550,-774,-531,52,431,10,742,526,113,-771,-862,79,-214,962,-836,-126,174,470,853,715,-43,162,-859,330,23,585,-285,-200,592,826,774,-564,-2,-762,-487,617,996,-404,300,794,354,204,-643,-631,-766,830,680,-434,392,-302,959,120,365,-442,-145,797,873,339,-502,10,-26,58,85,-860,-558,441,422,584,92,651,-840,124,889,592,211,-272,-378,-950,-470,844,-283,-86,726,-672,241,-296,-478,-459,-973,-229,-387,316,220,-278,-78,725,-185,522,-712,-623,-786,368,-159,-282,850,-826,-974,309,-816,-49,499,414,-219,819,-811,88,-504,522,631,-494,-489,899,185,-326,860,-236,814,-607,-913,-491,842,-93,-154,-622,-714,-90,-694,136,-954,558,-847,571,181,756,783,-92,-69,924,-420,-587,810,-434,208,-474,430,-205,583,-142,923,-502,293,-325,-769,-761,78,919,-446,326,-525,704,424,485,350,220,408,-197,-528,-67,-329,-39,-723,-571,-746,128,336,837,-204,-618,690,-989,-980,-949,-138,-783,-692,-115,-847,1,80,493,588,-490,206,-233,-781,175,122,396,336,490,-772,38,563,-281,472,-190,-69,640,525,491,-534,-397,849,-499,-767,-100,477,-38,-853,-354,660,51,225,630,-53,-422,268,823,-67,-342,517,-714,-834,-994,70,-18,-372,837,-84,-80,307,-568,562,-456,140,-51,841,-854,855,530,-482,-367,604,963,-163,-736,992,-967,636,438,819,77,-421,-202,616,425,-868,-30,809,534,-496,768,-112,-797,-810,307,-282,330,42,14,-358,276,361,-472,566,178,56,82,-353,-966,-711,250,514,478,987,571,-230,339,197,540,277,-863,-177,366,-414,-847,960,135,-766,264,-123,287,-829,-211,-241,330,-303,-666,-216,541,-972,-260,-52,442,-76,296,-972,-58,-223,-238,-445,206,-104,522,-740,919,-557,-592,-199,-606,-261,996,-999,920,-766,-709,-533,554,-744,251,-24,-386,-470,991,101,-638,-263,89,724,881,-175,253,813,-259,-27,204,31,89,-29,-27,940,648,-82,728,305,-2,741,232,263,83,815,-203,-141,740,-569,-849,-755,-36,328,-443,-86,882,758,-47,942,360,-676,-115,374,-534,-746,-723,-494,-621,-896,989,-729,841,-372,812,103,-453,-402,-847,-176,-107,-573,905,-304,-930,664,-658,664,209,-909,71,950,-22,668,64,899,107,-556,532,-77,-340,-149,692,383,-214,88,-111,261,-968,-675,366,257,731,549,-818,-181,36,-632,-135,-781,962,-841,65,-859,-131,-77,37,661,-487,450,-926,657,947,539,700,-812,-578,-828,-772,-893,860,-424,980,-986,122,320,938,716,921,-69,-723,-257,800,-216,439,-643,611,-242,519,677,-933,-332,-267,-81,-548,401,-227,-666,-702,-575,-204,877,-577,-280,35,457,-730,-841,-331,-152,-932,-244,-988,-535,-383,-372,213,-894,-657,43,-69,225,323,919,697,-707,-830,-857,144,120,-953,-45,890,504,573,847,-956,501,-487,-931,-667,511,-718,363,-686,-152,-599,801,-592,-174,129,813,901,151,520,271,-586,319,772,-894,-60,-887,928,281,-85,911,310,-119,969,-793,-517,-376,480,203,-394,-834,887,38,-527,-717,-338,-975,887,-642,92,-110,-450,-436,184,174,-731,528,156,-815,-716,214,-186,492,-588,-653,98,659,-593,-98,-137,875,345,756,-19,582,547,281,204,966,801,181,-932,981,-609,546,-28,700,246,-184,271,-766,101,-712,-195,-772,-804,-606,460,-348,262,-184,-616,78,28,49,342,541,-953,-358,-443,191,-611,236,-379,-912,209,984,176,941,78,-547,-609,-854,823,-141,650,-744,-288,888,-703,439,-628,625,998,641,-353,103,-84,-575,233,697,-153,-264,-499,172,302,207,517,-718,562,-211,-395,343,-747,-144,-745,82,-966,-133,606,882,735,-894,-946,-869,596,160,-803,899,311,339,126,-422,-222,-199,492,600,213,-920,-606,-219,964,464,174,840,-187,537,588,618,330,-602,969,390,609,288,-254,-257,-513,-548,449,351,-793,946,-935,526,340,-450,250,-150,-208,-439,647,393,-549,-680,124,-515,374,543,528,-812,-552,776,92,-969,-5,-132,594,391,878,75,308,263,25,946,325,-252,-590,109,-766,-9,-90,-404,-561,902,437,-427,-152,-129,-614,236,143,-275,457,-645,-523,367,734,654,786,-155,450,-138,801,283,-383,-217,-511,347,-956,604,789,-387,194,9,-920,-933,-736,402,865,-784,11,-395,918,-379,-751,-125,450,158,891,449,-486,674,-679,145,-373,-919,534,395,654,229,-86,920,170,10,829,108,-77,-710,-432,34,423,671,-875,-958,-218,-377,-252,-598,390,669,-732,-381,-60,787,-87,17,-246,958,-968,-693,354,595,238,-436,-883,-606,22,798,-427,24,-5,678,580,-652,-55,-908,746,484,376,-201,-291,-524,-27,-830,-661,-747,-66,629,-594,414,-820,908,856,-164,255,-369,-748,71,590,701,126,-760,426,-978,330,-239,-800,59,-837,292,-142,-935,862,-607,142,-70,-532,-434,79,-882,329,627,995,-832,839,-436,699,792,362,924,722,870,478,255,-558,790,-745,417,-608,-10,956,48,900,211,470,391,469,-897,531,-25,466,-910,757,339,172,325,-765,-15,250,615,476,-521,93,-849,732,904,5,999,766,-922,563,-428,-629,-700,663,757,-447,35,-243,-859,-810,866,2,-830,989,-614,-944,842,-3,620,41,-487,-903,-310,481,-899,313,-427,-519,-121,-332,-463,492,-54,767,-87,-835,675,-145,-117,495,-62,-192,-859,-708,742,503,944,-956,724,-195,-985,-699,883,-660,906,66,199,-349,245,-220,72,990,326,43,673,-14,853,-881,140,432,768,309,-302,157,-935,-51,-32,-352,-767,-458,700,881,854,982,-675,-767,221,265,195,139,-342,383,516,567,417,846,-148,-98,-922,-645,-718,352,-603,-912,804,356,-840,-708,794,475,-730,489,-69,672,-493,241,-586,-839,30,-367,-580,-791,-625,-108,-183,740,239,-933,-309,24,-135,338,-645,80,852,722,290,678,-73,595,747,501,-636,935,631,-101,-759,107,304,-420,-286,548,-809,201,607,958,-431,-996,373,-786,842,229,886,-290,742,-2,871,-681,-847,198,811,-301,982,-206,-382,-138,886,250,847,-492,-695,164,-795,-228,226,803,172,-267,849,338,-489,-296,115,954,935,-413,590,293,142,677,-431,-613,327,-450,553,707,-170,-772,-314,829,-36,-382,888,261,715,892,-108,-197,-131,-652,90,-859,103,543,-108,-660,969,329,973,665,-953,148,348,717,883,-630,442,438,-850,824,-475,971,-508,410,431,-384,-529,200,-372,-667,-177,171,-878,543,263,660,647,358,-739,-310,-963,530,-738,-528,-211,805,459,-883,139,855,-136,-322,458,691,-514,899,78,326,-80,-25,-240,704,811,157,312,-840,-890,-763,416,232,395,729,716,158,-674,357,836,147,-860,79,-950,-711,-743,36,294,354,838,359,685,-758,725,-87,-970,-812,900,-696,-499,3,299,-525,548,-563,-646,336,-950,222,-444,-751,-183,-300,643,-22,583,639,149,-153,664,-439,-964,864,39,-954,-990,877,-85,-357,-611,440,58,43,-439,790,498,688,-826,223,334,610,-955,56,44,-524,-347,932,-150,848,-670,-266,695,122,67,507,-805,309,215,-327,5,-549,818,56,-12,-349,-585,777,-250,585,-381,-461,916,-21,-585,782,-645,-213,722,48,295,172,291,-365,378,126,-978,-331,647,-84,-301,900,-351,-130,-410,561,358,-561,706,-240,170,312,614,57,-756,854,-7,-570,542,-920,-407,-872,339,-966,855,-999,-762,-944,69,516,387,117,-133,-94,-657,-119,-499,979,-903,-337,294,591,-268,-925,-607,842,740,-890,-213,-495,210,942,-437,-577,753,40,-206,-216,881,-892,-805,118,-849,446,674,-110,836,41,-270,692,444,-974,-541,676,153,-886,-641,-202,808,-109,-246,-566,-35,452,-670,107,-899,-76,-844,311,-642,-423,-300,6,-48,-964,392,-364,-47,404,591,917,-303,-208,458,-665,-15,-42,-231,233,-12,943,112,686,756,-918,-41,319,534,164,977,845,229,-370,-578,-869,-939,-923,-151,969,-225,735,-708,-551,-168,649,-960,-652,-387,-607,628,737,196,-201,-684,-787,-173,-657,-482,-271,-111,-713,239,253,871,31,511,446,-685,-167,50,-659,639,223,511,-977,325,-750,-97,813,-655,-172,569,370,126,885,-199,-725,657,424,-517,218,652,175,-1,-244,-909,-407,-325,628,-147,893,-599,504,-575,553,-141,886,-834,-206,-7,-36,663,469,-224,746,399,218,-307,29,51,122,979,-944,349,545,519,-130,-459,493,-392,992,618,-256,119,198,887,-908,852,-643,129,333,-78,812,-308,-923,630,762,707,380,556,-922,443,688,294,667,673,484,911,469,-683,829,-722,-113,318,68,544,-215,558,-224,-877,-175,-84,355,-870,733,-10,804,451,574,-131,-915,301,-891,3,-27,-545,-43,-102,227,863,-863,270,-732,-523,974,-624,-796,-844,403,-168,-377,-892,982,-927,771,-22,288,879,354,635,751,-964,-353,-158,898,73,875,510,559,253,-594,-902,-541,-941,-631,956,-432,-938,-623,-699,558,-279,89,-818,950,488,724,-749,688,63,215,830,-664,942,-801,-162,774,670,410,-394,-392,773,362,-425,694,-533,324,-105,-545,177,794,-432,260,923,233,-880,939,-643,641,-126,82,828,979,-124,519,-674,183,-36,583,13,-162,538,298,885,950,-72,-857,30,-514,-597,-540,166,-935,376,834,306,749,-468,349,-248,382,644,-339,450,731,-1,-893,-633,609,461,-904,-349,-276,858,580,740,83,-696,-461,-272,-70,-389,284,122,-338,-696,189,170,683,-687,127,165,-393,-561,471,725,-917,-358,-723,-561,252,-368,-987,-48,-372,132,788,-676,845,328,-261,213,225,240,428,502,368,874,-859,-142,262,781,-255,11,-616,609,-824,617,-441,903,-691,707,311,450,360,-170,428,-473,558,844,-957,913,-837,442,-94,537,737,-836,148,-376,607,-122,572,189,-675,-228,-269,916,-409,102,335,-695,-940,-924,201,895,-382,-542,186,-763,-70,198,469,455,924,-777,772,-164,704,-896,813,943,909,-559,-902,231,168,221,891,533,-606,-345,-283,79,524,-734,-706,-76,-451,248,-994,226,722,-295,30,-33,94,-68,-19,-684,42,431,325,843,436,-929,-504,928,-610,-873,-123,779,966,-68,-810,-978,708,468,-684,-557,325,-510,65,584,-230,767,-941,57,-732,-945,249,-472,-82,-797,685,670,319,-317,-617,958,833,136,435,691,967,157,881,842,599,179,41,586,-211,675,283,-163,556,-504,-682,857,643,435,-457,831,-293,-185,466,-860,270,29,527,-21,936,822,833,-732,480,504,-480,-18,-686,749,-439,200,-734,680,-702,-656,-740,998,939,737,387,36,-492,-595,-200,-494,278,346,-489,35,-130,541,-431,-921,-497,657,673,-323,354,929,-609,932,55,-12,-207,124,-10,-554,-279,593,797,-433,-549,-660,4,-381,266,25,-596,-286,888,584,263,-422,-254,-582,930,948,-1000,393,220,882,-88,578,-896,-536,283,329,194,-786,-558,-162,-22,-873,-707,-809,877,462,436,651,560,615,314,-806,128,927,-279,916,908,-905,165,447,-164,107,613,270,-12,644,-255,965,-927,-751,-245,768,-179,-93,125,630,-192,-391,-200,-168,-92,313,784,293,688,547,307,-364,200,639,-314,194,-892,461,314,676,705,-504,-353,-891,134,-425,-541,599,-955,-148,468,286,-971,21,214,125,-109,100,-569,-930,-328,-847,387,-272,-647,506,180,243,988,955,-172,-716,941,607,11,-78,455,835,538,-775,-245,348,864,-514,631,-640,725,365,116,282,-762,-58,-850,-466,-534,-952,-557,348,322,-1,164,-448,103,231,-771,-735,262,-94,327,-49,-848,-190,361,490,607,304,557,-858,649,-322,316,890,240,69,548,510,-191,-696,822,510,279,453,-21,589,-553,-818,980,-221,8,911,-824,5,95,-404,632,748,104,-926,-13,-345,-241,893,943,-539,-655,639,601,841,-165,-277,-247,379,619,169,-904,-376,452,151,-726,458,-177,690,-746,223,-149,106,728,908,19,615,510,749,-12,685,-581,857,613,86,451,695,889,-523,-249,293,419,-898,362,244,-746,-539,-366,298,-76,-11,-890,106,-449,-26,813,622,544,-526,-357,-897,-248,337,-943,135,-419,564,-546,-488,87,-872,-343,-495,666,-966,995,887,356,950,155,139,-528,-907,686,-170,276,-630,-51,-178,-759,181,-90,-828,376,-717,344,-902,726,709,135,-985,565,-183,-913,718,172,602,267,-739,585,306,-119,966,568,-28,9,-775,-868,177,582,-470,774,250,670,-804,755,-850,-496,-83,558,-663,-643,-623,958,-169,742,-236,490,608,868,170,265,-34,-763,155,-339,-777,382,-116,-660,771,202,-792,834,-538,-457,185,710,634,-66,-537,352,-959,63,-816,-851,-582,386,454,458,-783,-97,-985,248,-366,-730,839,481,630,-712,53,-806,822,-834,216,522,-76,568,-312,-218,579,730,-707,595,-799,636,653,849,-417,665,-123,764,-319,219,-949,486,130,725,43,270,961,-451,-614,-530,831,-182,780,302,251,-163,-968,-932,864,108,-304,-702,115,-885,870,-943,363,-43,935,-36,416,219,755,297,877,-689,330,136,207,-536,-415,-464,-938,329,-849,689,319,502,-948,-14,-44,-590,-244,268,748,977,-376,168,311,-22,-319,809,-165,-364,214,-598,-831,596,217,-963,92,39,-233,-371,-764,-883,-524,-327,753,-719,306,-63,-561,952,864,-501,-337,567,-515,-356,-378,49,94,-772,-284,445,620,-2,168,153,42,-778,873,602,-983,-850,-656,16,-231,515,601,304,-756,-397,622,-717,471,798,-54,-60,-378,-75,656,-429,-741,440,-549,320,-917,889,-571,-45,790,259,809,-220,-112,34,501,594,324,964,164,-416,-120,-713,-715,932,797,-334,-731,-600,-77,-79,-42,-713,307,194,-436,399,-994,-563,557,-382,321,514,-871,327,600,857,623,760,19,398,380,-955,83,-118,943,132,-69,-923,544,-372,-347,610,19,360,532,-11,602,601,198,-734,833,-377,782,354,-826,609,865,-944,824,-752,-470,223,-329,-621,263,112,-674,-673,504,173,-354,-639,-309,-410,562,-329,484,405,-47,-758,-277,-680,49,960,432,939,-225,651,967,-469,204,-771,65,124,-30,642,40,-267,614,46,-165,938,-730,763,21,104,-785,999,921,-383,-56,582,-958,997,270,-824,934,698,-360,-189,-64,-111,271,-559,-767,-7,238,-382,-271,563,609,-370,-289,980,-962,-178,-437,490,-577,-523,-155,417,845,-893,-969,-676,139,584,307,-90,-982,191,-636,-402,817,565,134,-130,-741,664,4,71,914,955,579,-89,269,-244,242,-93,251,-279,274,-897,639,-398,123,-855,461,-441,109,969,676,-622,771,-823,356,-656,304,-318,-147,582,-920,481,468,276,-440,79,102,-973,745,-64,89,527,477,-465,-36,-686,-229,316,-448,643,-5,154,74,134,956,-316,877,-765,-205,946,-443,-379,-547,111,-571,-31,433,-405,605,-962,-646,-700,-834,-608,460,-356,-358,768,278,719,295,460,102,-844,929,-167,-419,-270,-894,498,661,-63,256,-854,-624,516,-979,-959,-185,-318,-711,-891,441,353,666,-593,-47,-540,-876,-486,549,-371,-37,125,407,-478,-581,407,464,-680,113,866,349,951,-357,591,227,-506,-720,803,75,865,407,-345,817,939,580,856,189,-991,978,-584,353,-175,-176,532,544,448,-580,-574,-792,-402,-910,265,584,-403,348,776,279,798,-41,-121,-9,663,834,-258,-358,-931,757,355,343,605,-862,-732,38,44,277,-6,311,-124,-250,513,785,799,-15,-731,-488,601,343,662,-875,599,-811,-923,584,850,-834,-89,-454,-929,938,-238,271,-695,267,-936,146,455,431,783,-486,-53,557,170,-704,954,-186,948,677,459,340,388,450,32,-871,189,-371,537,123,-780,-595,793,-309,-184,6,-934,206,106,-448,241,649,934,382,846,662,-338,578,-173,-424,-730,578,466,-389,994,-592,436,-31,236,-924,-146,-999,165,-542,33,-36,606,507,56,535,476,116,-298,548,178,-435,511,965,280,142,-306,263,-664,295,649,843,273,596,96,-177,683,-684,-226,829,-590,741,765,-559,-262,238,93,88,22,680,-584,768,800,973,966,676,-786,-916,188,533,-310,-346,276,-862,-543,-241,776,-393,97,37,-639,196,698,121,463,-833,-129,-501,-657,-570,550,162,-431,-948,-643,-893,-532,900,-846,524,-66,561,854,744,-105,-767,-949,937,-700,-763,-180,25,738,516,-211,-165,-850,-58,184,746,706,-626,242,-275,-347,13,471,610,-659,580,-955,-205,-563,790,979,517,-576,198,307,-585,-16,450,-185,728,-703,-671,823,-761,250,790,601,681,319,-10,-605,251,519,942,426,72,153,931,-778,-902,-924,806,-885,-667,890,771,130,950,-428,-562,919,-889,976,-294,-857,-491,935,885,-785,-574,848,903,290,-298,975,-384,749,-479,-371,352,-439,960,977,622,-942,-56,-887,-556,934,845,-88,44,943,429,-135,407,-373,-892,833,866,620,-559,-833,848,984,0,722,-620,-639,766,-639,-235,-487,-422,-51,-152,-822,-674,-682,526,-456,706,-659,866,870,-334,764,-432,-527,-734,980,-310,982,-739,-994,-563,896,-568,5,-480,315,395,804,904,967,704,-238,-803,-850,534,-431,980,162,-603,442,762,-290,964,-24,-119,933,631,-874,523,766,-143,715,-190,425,431,145,-333,-979,-948,601,-572,-401,-288,-471,34,719,-74,-499,-614,940,-679,795,899,872,856,481,419,-20,-789,-57,-940,260,-803,-574,809,-57,923,931,36,-289,386,-71,291,889,788,159,-754,-540,-772,773,-900,97,799,-732,490,420,-832,415,-237,-586,-5,-265,147,-579,493,-561,-887,801,980,598,123,-176,138,588,427,-291,-98,482,-869,603,-71,-859,-217,-967,-473,-130,567,386,-239,469,-877,669,536,-590,362,593,-516,-140,-385,698,-875,-812,-305,-349,395,998,-831,-16,-177,-165,476,-641,-405,-763,395,225,-546,-627,846,144,-187,311,-67,682,993,818,300,-132,-490,-623,-201,-38,-389,-38,-640,900,-174,-272,761,392,-384,212,-632,-873,230,470,-720,-708,-779,227,-233,541,501,-109,-88,-657,709,985,898,-611,983,264,-931,491,-688,19,697,-882,537,-291,926,602,-565,-217,-571,-96,461,-952,-874,467,-249,-609,169,21,-532,-157,572,402,-74,-24,816,553,449,972,923,274,715,574,-65,352,953,410,207,572,-886,-366,825,-512,561,689,381,-923,584,-252,-711,-41,-54,-704,-661,39,-324,353,-851,995,-558,-762,-44,-973,-409,-34,694,409,-848,415,-238,818,-469,-132,-236,-928,-220,-3,806,381,167,33,350,-962,-375,-417,56,-171,-752,-232,48,-509,573,651,-131,-683,713,-770,-226,-331,-32,-574,-550,961,455,467,-716,-276,359,659,953,-293,-208,990,18,822,-978,908,472,431,368,911,897,766,-347,115,-247,744,233,-612,799,-847,-139,-95,-700,43,258,-797,196,799,737,-524,-164,-368,914,-998,-239,894,-906,979,600,-847,-285,751,-183,-444,-792,121,447,435,-303,-860,441,78,515,-773,-233,395,-709,530,-321,209,800,21,-193,-120,-456,23,-989,-234,119,-648,-163,-447,-107,653,392,-755,-766,283,-921,-853,647,351,683,251,-577,20,434,-868,-657,175,510,-748,780,9,-253,897,-139,281,-401,-541,-848,-836,608,843,-243,994,634,-619,-118,-494,39,161,57,-889,655,-439,-768,-452,474,7,904,-834,810,-34,-413,-137,-656,907,17,-149,-596,306,-477,215,969,930,-66,-144,860,-820,236,-149,-144,674,-120,-228,-359,4,635,682,724,968,-759,272,-615,77,251,-606,164,-324,728,-793,-147,697,-827,307,381,-320,-230,619,564,-63,775,806,721,180,160,-377,134,-427,-177,-273,-579,8,221,752,834,-515,-114,-932,706,-543,-207,132,-147,-270,641,214,-114,723,-463,577,540,86,-442,779,-505,-967,419,-805,197,298,-580,320,922,444,-333,-346,713,-131,-867,-217,-23,852,-128,970,316,-866,-672,-736,739,130,-198,265,-266,-477,-6,-627,886,-736,-520,383,343,-116,-521,722,165,-662,582,228,498,-338,-927,383,497,417,855,882,-338,-851,859,576,-250,353,-655,-744,749,-243,827,984,-38,-835,30,-468,-989,-535,633,325,-379,664,-43,-807,-200,-523,924,271,222,720,768,-92,998,508,738,-701,-853,-372,932,-275,-118,-34,420,642,305,311,-517,-138,-134,407,-748,651,297,95,-794,333,524,-944,116,-958,516,653,-413,-123,431,939,844,793,-875,345,144,-348,398,-373,753,-286,-593,-460,919,-224,-48,371,-850,534,376,-578,8,-136,-145,-542,-313,-469,569,-881,235,-914,-850,764,600,587,11,28,798,487,-239,237,-20,985,-117,382,253,332,478,-124,-50,84,954,-525,671,-555,129,153,965,-362,-52,358,663,518,254,939,163,230,-498,-870,303,-477,763,842,-163,984,828,278,221,476,-752,-47,372,812,792,904,-115,715,-133,711,-728,983,-293,-725,-544,-187,633,-349,-566,658,189,103,341,59,441,-803,659,281,-711,667,-79,0,826,612,991,-867,850,481,-186,-94,-855,-719,701,-51,697,311,695,924,578,839,-889,397,-655,317,246,214,139,-840,-639,-914,-363,-898,68,-480,457,659,-759,-584,209,611,-15,-785,-443,-929,-322,501,681,-235,-251,488,-277,479,-584,-477,-48,-913,674,762,809,729,-40,-424,737,264,269,-55,-975,-908,-39,448,227,413,-656,-886,-102,-162,-926,-129,-131,-327,-917,-401,-961,-841,472,-115,-703,-116,-745,-410,-404,747,661,815,563,176,-870,-992,204,963,723,824,-529,-75,281,883,51,-860,499,326,691,833,-246,-327,44,-899,763,-796,-314,-671,480,-948,492,392,93,536,-828,715,678,-896,-886,-3,-602,-663,521,-611,-166,765,-991,191,-392,378,-890,231,920,-399,573,675,-412,770,284,-287,-691,944,-673,-820,516,181,-419,606,-579,476,970,-750,-448,810,-446,469,-9,373,204,749,235,-556,491,390,728,447,389,-566,71,300,667,-42,-130,409,-285,418,158,19,-361,465,72,-570,-12,-515,-474,-607,-619,-328,-211,-288,-258,663,-349,433,-272,960,650,-924,687,380,380,432,-178,283,-102,911,-703,110,58,-562,230,710,-602,105,-309,686,230,-392,699,-107,911,-743,276,-613,-832,-55,210,-121,447,-824,-992,290,-55,428,2,-69,66,993,739,107,392,-769,-995,528,49,158,-54,-626,-124,948,-844,-791,754,368,-92,-73,-38,-983,-251,859,178,-80,-855,419,849,-97,-225,785,-904,113,286,494,442,700,-234,-519,-715,744,-453,-503,805,354,0,880,882,-440,250,591,-565,-28,379,274,-804,-685,-530,983,-468,-711,-203,-739,796,-887,-747,190,-645,-215,120,-646,178,796,-565,838,598,-287,-139,461,-773,-497,980,11,-267,-548,561,629,-981,657,-27,322,-351,987,-459,-79,-437,525,-35,682,-251,-311,-884,-662,-163,-441,363,427,-906,-265,-894,856,351,328,-585,645,543,154,-189,-859,-577,423,452,-775,428,-831,725,-224,33,972,-672,-434,-593,79,777,-298,-339,397,-200,928,-958,248,981,-70,-953,821,521,964,-535,-730,717,877,46,-753,-740,489,510,-882,111,-606,19,-583,-486,485,452,95,-558,-338,-261,479,-660,584,-838,417,-247,-835,84,585,-448,11,329,810,-979,-479,239,-928,333,-980,153,-352,319,87,-162,166,144,393,442,-566,220,163,567,-461,519,-204,305,991,-393,207,493,-473,967,-829,839,-658,110,466,663,656,136,76,-511,-975,-995,837,-205,-699,-223,-195,-76,111,-71,-382,964,-389,219,360,881,-666,-998,-453,459,329,-213,-982,-938,746,438,-234,-704,984,130,-494,-926,-320,-106,272,-816,-428,-532,-109,314,823,-758,-581,-554,-99,580,-761,-723,-608,-809,810,922,-944,-740,-904,344,-513,873,96,-852,780,-456,816,803,-760,-529,-295,-876,326,724,627,-716,-67,337,-743,-815,193,-179,-523,-29,-787,873,237,289,604,-989,495,-375,755,-9,-139,628,145,-122,-715,-774,491,256,-785,-410,114,-407,-870,863,-760,659,231,-170,-723,612,516,523,-147,744,-360,-65,-853,-563,-36,199,732,869,-474,608,221,-613,-367,-865,756,-470,588,-996,-855,388,-642,-566,200,-826,176,62,166,726,-774,-65,-420,-829,841,-560,-740,179,65,-533,685,-455,960,168,-691,871,173,393,-64,336,-668,280,-142,827,7,313,241,-650,-861,-775,-591,-319,819,193,-854,938,-595,-333,150,-399,282,-643,-314,-160,-821,387,-326,-933,-236,-704,665,-437,548,-766,329,587,431,-531,477,-595,115,-720,-53,737,-3,431,107,-141,452,-359,-964,-568,-286,68,222,-117,751,231,5,152,794,653,68,118,-557,229,164,-471,753,395,205,-557,673,9,332,-305,-99,776,-229,-532,615,223,-456,-587,-878,-820,-714,447,460,-31,969,-255,-500,429,277,-84,-737,-191,736,355,751,958,749,-869,-349,5,-840,676,-471,332,209,-276,-149,-400,624,-165,50,835,-452,426,5,-150,88,227,905,288,668,915,791,-101,-509,-803,-235,411,-818,-482,-863,-175,-875,-885,541,-610,-123,-698,-668,-597,431,-876,-33,385,729,-294,530,-60,-34,933,235,813,634,893,-146,296,-412,907,-360,676,650,-632,414,-848,-283,203,437,723,-450,269,-94,685,-779,-585,-600,392,214,-73,889,-170,-904,-725,855,-468,750,709,-656,-925,-645,-184,795,-966,238,-38,887,-727,554,-774,899,847,-793,-85,464,-71,851,404,280,209,-320,-549,-756,-565,135,-537,628,254,12,-926,-800,-537,-6,-897,-607,-579,633,-379,-764,-778,-355,-130,8,909,-622,80,360,-581,-456,328,838,429,-642,-991,-232,-600,562,348,-432,-686,910,823,-560,-432,-648,-802,22,-957,-97,561,-721,-315,907,-670,597,-916,-20,532,-592,-833,-520,531,30,-873,-844,96,-622,92,98,478,717,-884,426,-910,-83,210,-554,-650,-81,-902,-153,489,427,-266,909,-609,-753,374,979,-783,637,903,909,-302,67,-882,130,-376,-253,-892,831,690,203,499,-59,953,-793,922,366,170,-321,356,12,117,123,-135,-782,-107,-705,-390,-189,638,766,-184,135,691,-250,-543,986,637,-148,681,931,-675,-608,-992,-535,476,398,569,299,311,-240,-718,-364,406,-388,-536,942,-756,972,360,701,-100,-436,-676,-734,154,-664,315,-722,902,325,-748,-233,-915,979,-835,-708,-399,829,-654,-39,-506,-908,-797,416,691,-542,682,237,-852,-315,195,-481,-25,-380,904,670,756,-813,-727,-67,928,-455,690,149,-203,-20,-663,742,1000,-390,178,-86,1000,-440,-461,919,243,759,879,-259,452,-122,757,828,-286,5,-224,641,-446,927,299,-496,-137,331,-955,970,-17,685,422,689,567,-238,-190,-375,241,-333,-975,61,-215,735,217,990,959,314,666,555,-46,998,-647,-408,446,-718,834,-371,-236,-266,-997,364,-291,-617,504,-647,-938,21,88,-451,872,574,-122,-162,-815,-495,-734,-975,977,-597,-948,50,488,-445,122,-769,-246,-846,-383,232,-75,700,598,-619,-22,-375,-952,-641,-527,196,713,244,773,-347,100,460,-915,877,-960,442,-983,709,-644,-387,-333,-391,311,864,-495,-80,150,-868,-658,-58,-139,-647,-719,388,-978,975,373,426,331,782,745,135,564,-438,484,-836,-2,-420,-321,-861,340,258,529,-703,-538,-924,816,-259,-535,-742,447,371,-506,603,926,-417,762,582,324,961,-955,-23,-709,-363,-533,478,-572,-258,121,38,-820,661,-99,-386,170,150,-811,701,601,908,726,509,-681,868,-971,-97,-874,-317,-599,303,-565,89,317,624,-458,-485,-685,-233,-338,768,-136,-513,-382,163,754,930,582,117,244,849,-478,495,-667,132,5,93,-353,610,492,-900,690,-191,-510,538,367,118,173,-448,-294,843,-450,-97,-847,-618,-210,968,-832,-843,431,-617,-292,-780,-381,-333,660,-606,-404,863,-812,-337,933,268,794,974,-932,-405,873,-689,-556,-107,128,-345,944,-420,736,-414,86,586,-854,-346,801,159,796,767,498,-540,-565,-380,701,-336,430,-834,-321,288,7,-645,680,453,-689,469,388,-458,-194,64,626,-319,290,279,-184,-958,32,-265,900,-119,-277,-260,548,28,-42,-756,409,593,665,-814,84,-969,-145,-318,-503,-298,960,181,6,440,-996,105,-13,72,-974,-906,-853,608,162,654,984,-581,-60,-54,109,110,-555,-998,-375,-341,-99,-842,486,-386,-108,-862,921,-384,-292,777,-744,518,922,-619,361,-22,-702,465,442,-822,898,737,-748,130,-859,-982,-22,719,472,-371,113,-83,630,-776,-256,-759,6,-842,295,718,850,678,-361,728,-417,151,-346,388,-943,-915,919,-48,-840,-309,-646,-655,-734,733,641,509,88,-962,-799,-155,-353,190,121,-206,514,-477,664,177,-576,339,-172,779,931,-396,-33,-737,480,933,538,-639,142,4,514,481,-785,-315,-770,663,595,993,-808,-898,-904,-253,-662,207,-965,-405,219,-55,998,688,590,934,42,-393,-949,-166,-754,-449,-637,650,-276,-215,-593,-331,539,394,-598,843,737,758,307,683,-251,-959,-973,363,-943,346,-671,880,149,-839,-131,130,673,324,77,98,-25,694,120,-903,-376,-90,-145,905,978,496,-47,993,232,658,202,857,-48,818,-220,-470,-340,970,-626,515,-335,213,-803,145,-659,165,-629,-598,494,640,600,420,-177,767,-377,364,139,58,-634,-205,-309,-572,-177,-225,-743,862,418,76,-841,247,-945,759,968,131,521,648,633,539,-870,-450,423,456,917,-179,765,-67,400,-920,-473,768,-521,169,-734,-538,-659,572,-298,462,-480,-997,716,-549,885,-89,122,-174,-128,670,482,-837,-71,-439,231,529,515,955,174,71,-487,640,-496,410,-217,7,-794,-2,-702,-997,192,-377,-341,-270,415,343,162,-531,208,-100,819,138,-693,-902,598,626,642,-747,-50,-247,-468,867,-805,-841,-982,487,994,402,-980,877,-975,466,-922,-817,890,127,-27,-187,-715,55,-38,-908,863,-198,780,-157,736,809,690,-167,893,-884,711,-824,-965,-165,116,-794,275,868,-23,-655,13,436,-549,-143,-376,-412,-194,278,305,390,-640,-808,-660,-603,-24,287,892,495,-394,-575,-310,-411,-524,153,-895,-282,992,-460,-603,789,-34,-770,198,-757,604,-390,-211,310,152,-937,-955,-69,706,-388,-821,508,-40,-185,413,-955,919,243,999,-760,177,135,742,-419,-869,-171,88,723,810,-616,581,945,-998,163,-919,843,-744,159,-985,761,-362,228,-849,-886,656,182,-960,-861,-875,184,-878,-667,593,144,976,145,-890,618,-275,-857,893,236,437,-964,-804,261,877,511,351,798,756,-742,776,5,924,-528,894,-137,32,220,60,-219,-729,114,23,196,120,756,-867,367,-336,892,904,-55,783,-843,384,53,-335,676,-996,461,394,-908,227,-189,869,377,312,-513,772,-622,-878,106,548,-295,-825,453,82,-443,246,-266,24,-523,-334,817,35,-172,87,-903,-569,469,-14,880,44,-806,-679,220,710,301,-311,-798,10,-259,822,-633,726,-925,533,-682,-397,-108,501,406,373,-593,383,-887,-73,498,328,185,334,38,-199,768,639,-571,269,379,40,-501,639,689,524,-666,891,-562,610,846,-212,307,-425,565,908,-679,-40,187,-849,-968,-670,-345,936,104,244,201,-117,-30,-136,790,-670,-597,965,81,-984,153,15,91,166,-177,382,914,555,-975,713,550,-701,177,-743,196,-818,-695,-691,-918,-701,833,-205,-745,344,-970,-515,-933,687,-472,-125,689,663,74,31,443,374,-475,-259,611,941,1,21,315,868,-274,71,-894,-292,83,-118,51,-252,30,791,563,-449,403,-416,-294,-677,125,-838,226,-732,652,-683,-440,902,591,361,-382,-902,198,454,-625,204,811,-372,-506,659,148,399,-306,-898,36,-716,283,-117,23,675,893,151,929,-950,-401,-318,-47,-544,617,973,-810,-865,-145,263,-195,-568,-318,-372,431,575,265,62,-362,-598,926,-793,-552,-900,-739,624,767,-377,20,-542,-728,-135,-601,979,-712,746,-707,-240,-56,-394,-162,175,-514,-487,-876,-435,-953,471,-90,-251,959,-347,-953,0,230,-180,920,-47,-146,-741,955,661,-894,509,-462,-253,-928,-237,-604,-108,-751,535,-798,592,279,-408,-710,797,748,606,-736,-331,680,910,-454,-745,-391,966,-160,-131,-268,136,-592,-473,341,542,303,359,530,-993,-204,316,290,-420,-420,494,356,-173,-770,694,-893,-390,-867,619,-404,-991,546,257,724,352,883,-217,-844,-326,200,-820,52,1000,983,142,81,-373,-924,708,428,-356,591,-319,920,306,399,-433,-543,269,533,196,-825,243,665,308,494,349,160,-183,72,-571,-733,6,793,-55,-688,-195,721,308,614,-44,999,487,370,-698,940,-738,136,479,-317,-733,372,-259,-178,391,-87,-584,677,-910,-899,-460,-279,-147,-907,573,-907,-209,428,-538,-991,305,343,756,-587,213,355,240,617,88,291,-71,944,-590,-521,458,-698,906,311,-270,757,892,-241,-604,573,777,927,886,-854,642,610,702,-997,346,552,-992,-472,446,-68,162,284,-54,102,-236,496,-686,-566,670,-286,640,40,-627,961,278,477,168,126,178,893,741,714,-670,-101,182,-871,512,-963,-183,964,-557,829,706,-175,-141,-43,61,234,313,924,-163,-392,726,-133,517,-24,-590,-385,-780,-883,223,435,679,37,-837,199,-3,102,-152,-526,-859,913,279,-349,-132,880,575,-683,-535,410,877,-391,-892,810,0,-886,209,-463,-676,-881,940,-900,-797,129,156,94,-213,429,334,995,-443,190,269,926,858,-603,-189,403,911,-2,-310,-119,-290,856,379,791,74,443,744,-367,287,871,-19,-549,-442,-480,-941,528,555,-583,-10,316,-294,793,-316,872,-182,-217,-995,-544,154,173,-31,-829,501,-463,464,-703,-927,-713,-371,-650,-210,-814,884,-382,53,-668,-636,336,243,-380,641,557,63,861,-963,-746,423,320,-487,392,410,119,711,362,694,-657,794,444,-208,394,639,-756,641,-68,-224,494,-465,-649,680,-220,-175,-566,-701,-800,-927,809,-951,791,-827,981,478,670,-387,500,-358,862,79,379,270,433,51,197,-285,-877,-873,923,-667,447,-326,-860,-797,-301,-661,-763,231,484,488,-744,-131,536,379,-221,895,416,54,114,-455,-714,449,-484,551,-342,393,-858,25,-525,841,-404,-405,-389,-924,-571,-563,-21,346,566,973,-367,466,451,611,-127,96,697,789,-738,893,-41,205,-54,431,461,552,-228,392,125,492,-169,654,-71,-877,-438,60,-637,-423,47,414,-170,821,-916,919,757,117,247,445,-699,-526,220,-838,159,-387,629,-782,373,-999,695,323,272,-38,655,156,-899,-628,86,289,-238,-316,-640,604,-947,156,-696,785,671,-102,-846,-163,-350,-783,-972,-377,565,-725,3,742,-482,602,-790,654,-160,-557,-625,-364,-425,791,-110,-864,-264,-801,-754,47,192,181,-785,-570,-731,-469,-56,-607,523,315,871,-665,958,546,169,38,-690,-378,-934,404,996,230,196,-377,461,-586,-679,104,639,203,305,742,359,-412,-570,-481,456,-362,-206,-662,-728,-363,863,321,980,-786,-662,-891,493,687,-428,743,-80,-539,-201,-846,-295,-546,460,578,-210,249,-249,730,-726,164,-693,207,818,820,-408,84,-360,-822,-590,382,-751,794,781,101,463,208,-491,-152,359,354,-777,-194,439,-220,-37,769,-610,-217,-194,614,554,564,-983,180,-274,-605,38,-909,-272,-584,-287,-366,-648,437,337,730,-425,-810,531,809,589,829,-208,-243,-725,-593,924,183,70,-740,63,-293,-757,846,962,594,349,-267,832,-108,760,964,-105,-376,947,-336,-851,-607,218,668,-646,560,258,-818,-818,923,-383,-881,-259,445,-510,-195,338,719,-492,468,476,324,-28,-464,831,-686,764,-347,-503,822,-419,61,102,-66,-905,773,-410,983,-379,39,499,-827,-130,-79,772,-986,-705,-475,-271,-936,-342,885,526,795,503,666,462,875,732,-12,-43,498,930,614,-549,-778,413,-966,-266,-433,134,-876,-848,531,14,-449,-262,-975,-151,65,-879,-525,-884,336,269,218,-938,10,-265,-402,-390,994,-86,16,602,-995,353,-796,-440,681,-61,431,-764,-316,760,-750,137,-428,637,475,-480,-786,410,-317,988,90,682,-345,445,-202,-918,856,402,-88,-473,116,137,18,129,805,125,-347,-704,201,-336,888,-305,710,-210,147,822,84,991,697,756,-671,-556,264,981,694,717,-705,-632,238,-997,606,-430,-581,737,546,-597,-34,-909,-981,-986,-600,-649,-727,833,-86,-475,-668,-989,438,502,-592,108,324,-669,-82,-161,869,676,-300,-299,-13,-191,-671,856,616,-738,-345,635,31,-760,289,-701,499,-919,248,-86,882,-249,404,155,-702,767,-980,-75,390,402,767,-767,508,575,557,-88,-274,775,-35,-466,-376,452,184,733,35,427,-426,-299,994,-925,-431,-595,-835,-216,-172,493,522,105,-421,347,-823,-960,-38,732,-123,-923,769,103,-988,-416,454,875,317,-204,51,-558,260,6,-327,898,-550,520,-830,-990,-119,-708,-394,399,-360,-183,27,757,462,-611,703,620,946,301,818,103,221,817,102,-984,-958,-6,-687,-822,200,-728,569,737,-792,251,-7,797,872,658,-774,917,309,953,354,958,-547,847,69,120,783,307,-374,516,-116,-472,-207,647,-215,883,442,-868,153,-313,871,-599,722,547,-209,95,-608,186,-249,896,187,-410,-399,-755,-899,734,-234,-988,594,465,-700,-609,-571,229,-981,789,491,17,-335,-933,-512,679,758,-213,-867,275,953,-528,-931,-60,-76,239,178,-53,-374,-686,-981,402,774,-654,391,-628,-696,-544,-224,384,-781,-863,-38,-97,-745,-334,-992,-387,919,-513,-771,-40,-577,239,-326,-904,580,-591,277,541,-39,-574,108,709,300,-529,925,347,-822,455,-428,-24,-956,-711,-133,-835,-728,-749,969,323,-681,-348,-284,-631,-224,308,-312,-762,-661,664,212,-863,-343,47,-225,-68,-310,-479,-51,857,-830,-551,-474,475,-824,-77,900,-406,316,-502,693,557,-780,873,-843,-272,104,265,-282,458,-628,216,400,-936,356,464,24,638,-106,-951,-42,-286,-691,-838,656,-857,-698,152,-573,-446,-654,547,505,-719,482,734,-613,319,-602,526,100,-802,666,443,-662,706,302,975,-199,541,26,-622,260,-220,-544,-440,246,111,100,230,512,576,-563,-453,916,-996,-666,971,-650,-37,-144,-929,45,534,801,144,-36,621,-200,903,-778,774,-271,-438,-732,-117,-636,-421,922,935,838,153,550,418,550,236,-152,-986,761,359,-537,719,-40,134,-352,-955,-837,-232,745,-426,117,43,-677,76,348,925,560,-150,780,559,-876,-269,-759,-235,-562,-72,781,-541,621,489,-879,71,103,-877,-84,-820,52,400,-84,-436,298,34,-624,-249,791,-120,-183,163,339,-842,793,-377,97,191,770,872,896,739,439,979,-152,111,57,-6,-540,146,764,308,-885,984,-663,185,688,-485,-191,280,-277,504,-328,486,-632,206,-344,394,733,-14,-476,807,553,-689,-476,-608,946,891,750,1000,-296,-870,557,-985,35,398,-643,-961,-545,-519,-770,-501,-118,-481,637,399,545,677,352,21,-970,-244,-511,187,324,-712,155,394,-6,-311,914,28,-324,-474,841,615,624,166,-924,-819,-120,-83,1,784,677,219,231,436,85,614,-377,649,-702,931,927,927,-307,327,692,910,516,545,-205,-679,-29,50,119,112,-227,689,-746,-49,-220,-144,-603,455,104,-253,-293,-324,-391,-626,-702,156,-72,262,-764,-449,8,-340,520,-302,325,607,801,-507,-244,-312,-574,-849,-308,-250,372,663,-364,597,-556,842,-986,765,334,-137,-9,-953,522,-648,-453,-475,-960,-819,-365,-380,-75,113,-739,445,922,-668,-524,130,-109,-742,737,-904,0,-6,49,-789,-375,25,-957,886,-204,971,473,-318,-388,-293,-763,-428,-224,-952,136,-685,397,632,585,543,-296,918,-635,224,-600,-580,-113,-795,-822,-426,706,613,863,-532,948,57,628,694,526,-71,527,-310,907,-630,959,855,901,-910,443,495,-447,-764,-408,-6,-338,-924,-588,-51,849,-894,585,21,34,-446,699,648,-411,-654,-318,-840,752,680,-566,455,986,-735,-432,-582,422,-191,-703,-65,680,-38,-859,-414,-656,630,564,394,-1,-692,-925,-946,196,-605,485,152,476,28,-443,168,-752,-346,-585,191,-8,526,931,-273,-671,-131,-255,-198,314,-843,58,409,-439,548,-488,-427,-96,-817,-202,176,-192,-719,333,-388,-50,734,-31,-406,-842,767,675,-100,-875,373,-779,30,-190,-3,-840,-45,235,-737,207,703,-103,871,308,-905,734,507,-956,959,-890,48,769,373,-365,-990,637,-495,-715,-872,278,-696,-7,580,-391,385,230,-582,-10,-264,-559,71,-338,-667,-353,606,-979,827,-226,-461,838,-407,276,794,-838,-995,111,-205,-614,-140,-181,175,522,519,435,-618,149,-757,565,-116,68,284,680,206,525,414,-44,-567,278,22,538,-310,302,889,-603,537,772,-724,-340,-328,476,767,900,-693,-627,-416,-798,-170,591,862,757,364,240,328,-613,574,286,-98,-971,-946,-684,-577,-571,530,-559,371,436,-688,71,-933,637,-831,843,503,-779,401,555,983,-174,-744,-317,-434,888,422,214,-358,-892,-172,84,-775,-992,-833,421,441,-11,-114,581,451,390,776,-926,-998,-980,921,137,930,-127,335,-894,529,-11,434,-21,-144,-752,778,-593,926,395,-922,-746,-672,-141,-927,666,834,181,-102,-989,532,-449,352,-608,723,678,-364,255,507,-676,-827,-377,-996,687,-914,679,-389,-471,-95,498,569,-912,-558,-306,364,-261,-246,-31,-965,125,766,-597,80,922,741,-796,285,-658,-293,-392,810,-690,-859,-434,-403,-514,961,-427,-457,696,-930,-963,440,798,298,-307,387,-736,-196,609,-262,545,-588,-821,956,-534,881,-847,604,-540,-905,-933,968,-126,-437,827,-632,581,-564,208,-231,493,119,877,-762,189,-80,852,-859,-23,123,-599,-798,-462,-331,-376,-162,578,33,-602,-5,-24,769,-84,-903,-924,220,-652,636,833,119,-412,-60,633,-534,-869,750,-84,839,422,969,484,-653,981,484,-692,480,-888,-345,-889,-72,160,226,759,871,-650,599,-962,92,-997,-568,417,211,-758,-434,-713,756,152,427,403,-189,862,-935,543,-81,382,-292,-114,-752,200,555,433,-516,-927,-922,926,982,-934,-161,-582,358,-348,675,344,873,116,267,-164,701,-869,-353,-263,-414,390,988,-295,-40,652,673,726,-205,-81,-357,-467,953,-152,-649,-667,-991,543,-606,948,-813,-554,876,-487,-886,463,338,-381,112,-854,928,-865,-202,248,499,-403,748,729,927,529,-414,-237,778,-358,-569,-715,56,-443,-896,-510,-423,904,-113,540,-900,142,-611,-58,450,-379,-407,-272,952,-965,-819,361,-234,739,70,-50,208,-364,11,-411,510,-564,-699,-607,316,869,-316,486,-977,-374,307,956,335,-741,-548,69,-133,263,-131,677,606,125,568,-855,-575,751,-442,706,-121,501,449,536,-667,-541,-214,-528,-165,-578,619,220,-854,-301,-238,347,-347,-900,-864,137,277,-459,947,222,808,-994,764,610,631,587,610,-4,-474,-379,206,521,753,-840,-231,-424,579,258,985,-299,744,930,7,-324,-744,-973,141,134,-699,-171,-792,139,-553,567,99,807,-658,-873,-828,-229,-269,579,-363,500,969,-825,32,-378,907,-786,239,-863,240,-736,753,-314,534,335,604,105,-40,560,-424,-543,-430,252,-305,166,-54,-956,-969,980,421,987,-268,-62,639,-342,-81,-432,-676,531,595,532,888,-68,-153,-444,940,-296,-211,-821,-798,-257,-228,-503,434,-997,656,-888,-275,970,-461,-511,-453,-657,692,-565,-714,-244,888,634,758,569,651,966,877,145,-192,-113,-150,333,-624,-344,549,369,-813,-228,-144,212,-859,29,-830,810,630,-82,447,500,371,767,41,930,-265,-232,626,941,133,399,-423,776,-861,73,232,-652,730,679,347,-207,-585,211,583,-941,32,425,-939,582,-217,-159,-196,75,-998,-130,-94,-689,269,-593,-827,-985,419,762,913,-483,-614,900,551,-695,-444,818,-387,-449,-155,-237,801,-672,-289,-993,780,895,455,320,-105,-56,626,272,299,-407,-239,-948,609,-887,573,-247,191,-273,-173,924,730,-864,-437,-7,-653,741,-627,-549,71,-537,203,977,-69,460,-600,687,558,-248,-11,-619,-872,710,-857,-890,140,388,-690,293,-954,-432,472,805,311,-900,712,864,845,578,-793,-704,-187,-978,-883,-981,-313,-750,564,-72,-13,311,794,351,911,871,-154,55,-154,-721,-271,478,908,-723,-867,-392,-657,-813,-608,959,715,-727,416,-615,513,-364,-658,803,-883,-328,894,-250,-41,388,-706,171,909,-781,286,502,171,920,-848,728,-184,-564,-598,-208,706,-922,155,-49,758,999,-630,-337,-989,959,-862,-295,477,669,-463,528,-175,-122,-553,-839,155,295,-727,251,-565,-638,67,556,790,-624,911,-623,155,-830,-873,-627,159,-273,834,-6,-641,-349,-150,408,16,-197,-293,-946,-254,951,453,420,-684,744,133,769,222,-167,-193,904,510,-412,505,-14,-146,325,-137,93,-810,38,260,-469,500,32,-658,444,676,-943,-554,930,1,526,-769,-699,953,-482,705,-884,-433,601,-986,-382,602,-955,-527,-960,-36,237,-408,66,132,-550,-329,651,300,490,-217,523,-358,192,-732,200,-452,961,-782,-837,-56,169,12,-308,-124,-393,864,-545,-872,-574,-774,-953,0,-806,-798,-442,703,444,-893,427,-253,148,-412,-630,1,388,-790,-935,1000,-690,-405,-859,-400,869,-886,324,211,324,314,107,-748,-648,-281,961,-405,342,-313,410,261,-620,917,845,338,988,437,-309,-257,180,-593,50,-910,965,458,-718,104,-658,-948,-668,874,445,-693,-622,-60,-854,-514,321,638,987,-527,-56,-251,296,704,-621,-12,312,-973,-589,691,-51,-578,-964,-280,-12,62,-126,-511,202,587,-973,-275,692,-803,773,-114,379,969,-60,844,173,645,333,906,590,234,-332,-896,-977,580,245,-471,-431,835,-165,922,-476,364,429,-674,-193,216,736,765,-987,-888,-221,-302,-387,528,-236,-703,-754,-669,-722,-186,-645,-559,971,557,-985,-463,928,590,713,51,-575,-418,-878,624,27,-612,-439,343,505,-499,-709,-153,-366,52,70,-36,-117,684,-423,-954,598,-40,-889,940,805,-296,-629,-81,-862,54,-98,-213,-746,6,259,-366,900,393,516,433,-251,-593,-757,835,286,971,362,-637,411,-464,-26,-381,-270,-663,431,281,-9,-247,-92,-120,-497,-882,-236,-445,-331,712,753,-124,964,-828,-372,65,516,-809,-806,-884,848,6,268,881,-953,-321,796,-864,-443,789,724,590,766,46,875,746,-844,620,466,467,386,957,-119,-716,569,-144,-592,688,764,-772,-891,917,-611,-63,-675,-914,668,-94,107,-213,-152,-927,299,-89,-857,992,946,-795,57,-165,345,-76,759,-451,772,-597,-642,-698,-264,99,320,-952,-906,15,523,-577,-224,147,744,-752,-510,-738,-405,-297,153,975,-27,12,987,-568,383,807,-236,-966,287,385,269,252,-174,831,522,116,918,821,-18,-506,202,-442,-340,87,-35,-529,-650,-273,-181,-543,-307,783,-886,153,645,241,957,538,-788,-745,-188,-888,461,918,923,943,-912,576,690,-972,620,-432,933,129,810,721,-870,-15,-143,191,982,997,-72,-53,28,305,907,418,-325,-548,391,-983,-459,-555,458,893,165,-674,-677,399,-225,-851,-293,-103,-382,640,-910,-250,871,-221,-285,220,577,130,237,-280,-806,504,-352,-789,-106,176,-665,497,-533,602,708,-843,65,-680,535,-684,-64,386,-368,-49,203,-849,-223,103,-21,-241,-160,922] 22 | 23 | s = Solution() 24 | result = s.pivotIndex(nums) 25 | print(result) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/13.py: -------------------------------------------------------------------------------- 1 | # Roman to Integer 2 | 3 | class Solution: 4 | def romanToInt(self, s: str) -> int: 5 | symbols = ['I', 'V', 'X', 'L', 'C', 'D', 'M'] 6 | values = [1, 5, 10, 50, 100, 500, 1000] 7 | 8 | value_table = dict(zip(symbols, values)) 9 | 10 | integer = 0 11 | # for i in range(len(s)): 12 | # if i < len(s) - 1 and s[i] in ['I', 'X', 'C']: 13 | # if s[i] == 'I' and (s[i + 1] == 'V' or s[i + 1] == 'X'): 14 | # integer -= value_table.get(s[i]) 15 | # elif s[i] == 'X' and (s[i + 1] == 'L' or s[i + 1] == 'C'): 16 | # integer -= value_table.get(s[i]) 17 | # elif s[i] == 'C' and (s[i + 1] == 'D' or s[i + 1] == 'M'): 18 | # integer -= value_table.get(s[i]) 19 | # else: 20 | # integer += value_table.get(s[i]) 21 | # else: 22 | # integer += value_table.get(s[i]) 23 | # return integer 24 | 25 | integer = 0 26 | for i in range(len(s)): 27 | if i < len(s) - 1 and value_table[s[i]] < value_table[s[i+1]]: 28 | integer -= value_table[s[i]] 29 | else: 30 | integer += value_table[s[i]] 31 | 32 | return integer 33 | 34 | 35 | s = Solution() 36 | print(s.romanToInt("III")) 37 | print(s.romanToInt("LVIII")) 38 | print(s.romanToInt("MCMXCIV")) 39 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/1502.py: -------------------------------------------------------------------------------- 1 | # Can Make Arithmetic Progression From Sequence 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def canMakeArithmeticProgression(self, arr: List[int]) -> bool: 7 | arr.sort() 8 | diff = arr[1] - arr[0] 9 | 10 | for i in range(len(arr) - 1): 11 | if arr[i + 1] - arr[i] != diff: 12 | return False 13 | return True 14 | 15 | 16 | s = Solution() 17 | print(s.canMakeArithmeticProgression([3, 5, 1])) 18 | print(s.canMakeArithmeticProgression([1, 2, 4])) 19 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/1768.py: -------------------------------------------------------------------------------- 1 | # Merge Strings Alternately 2 | 3 | def mergeAlternately(word1: str, word2: str) -> str: 4 | ptr_1, ptr_2 = 0, 0 5 | str1_len, str2_len = len(word1), len(word2) 6 | ans = "" 7 | 8 | while ptr_1 < str1_len and ptr_2 < str2_len: 9 | ans += word1[ptr_1] + word2[ptr_2] 10 | ptr_1 += 1 11 | ptr_2 += 1 12 | 13 | if ptr_1 < str1_len: 14 | ans += word1[ptr_1:] 15 | 16 | if ptr_2 < str2_len: 17 | ans += word2[ptr_2:] 18 | 19 | return ans 20 | 21 | 22 | if __name__ == "__main__": 23 | # word1, word2 = "abc", "pqr" 24 | word1, word2 = "abcd", "pq" 25 | 26 | ans = mergeAlternately(word1, word2) 27 | print(ans) 28 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/1822.py: -------------------------------------------------------------------------------- 1 | # Sign of the Product of an Array 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def arraySign(self, nums: List[int]) -> int: 7 | if 0 in nums: 8 | return 0 9 | negatives = [x for x in nums if x < 0] 10 | if len(negatives) % 2 != 0: 11 | return -1 12 | return 1 13 | 14 | 15 | s = Solution() 16 | print(s.arraySign([-1,-2,-3,-4,3,2,1])) 17 | print(s.arraySign([1,5,0,2,-3])) 18 | print(s.arraySign([-1,1,-1,1,-1])) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/242.py: -------------------------------------------------------------------------------- 1 | # Valid Anagram 2 | def isAnagram(s: str, t: str) -> bool: 3 | return sorted(s) == sorted(t) 4 | 5 | print(isAnagram("anagram", "nagaram")) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/28.py: -------------------------------------------------------------------------------- 1 | # Find the Index of the First Occurrence in a String 2 | def strStr(haystack: str, needle: str) -> int: 3 | return haystack.find(needle) 4 | 5 | 6 | haystack, needle = "sadbutsad", "sad" 7 | print(strStr(haystack, needle)) 8 | haystack, needle = "leetcode", "leeto" 9 | print(strStr(haystack, needle)) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/283.py: -------------------------------------------------------------------------------- 1 | # Move Zeroes 2 | 3 | from typing import List 4 | 5 | 6 | class Solution: 7 | def moveZeroes(self, nums: List[int]) -> None: 8 | """ 9 | Do not return anything, modify nums in-place instead. 10 | """ 11 | i, j = 0, 0 12 | while i < len(nums): 13 | if nums[i] != 0: 14 | nums[i], nums[j] = nums[j], nums[i] 15 | j += 1 16 | i += 1 17 | 18 | 19 | nums_1 = [0, 1, 0, 3, 12] 20 | nums_2 = [0] 21 | 22 | s = Solution() 23 | s.moveZeroes(nums_1) 24 | print(nums_1) 25 | s.moveZeroes(nums_2) 26 | print(nums_2) 27 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/389.py: -------------------------------------------------------------------------------- 1 | # Find the Difference 2 | 3 | class Solution: 4 | def findTheDifference(self, s: str, t: str) -> str: 5 | # s = ''.join(sorted(s)) 6 | # t = ''.join(sorted(t)) 7 | # 8 | # for i in range(len(s)): 9 | # if s[i] != t[i]: 10 | # return t[i] 11 | # return t[-1] 12 | 13 | for char in t: 14 | if s.count(char) != t.count(char): 15 | return char 16 | 17 | 18 | s = Solution() 19 | print(s.findTheDifference('abcd', 'abcde')) 20 | print(s.findTheDifference('', 'y')) 21 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/459.py: -------------------------------------------------------------------------------- 1 | # Repeated Substring Pattern 2 | 3 | class Solution: 4 | # When we concatenate s with itself and then remove the first and last characters, 5 | # any repeating pattern in s will still appear as a substring in the modified string. 6 | def repeatedSubstringPattern(self, s: str) -> bool: 7 | modified_string = (s + s)[1:-1] 8 | return s in modified_string 9 | 10 | 11 | if __name__ == '__main__': 12 | s = Solution() 13 | print(s.repeatedSubstringPattern('abab')) 14 | print(s.repeatedSubstringPattern('aba')) 15 | print(s.repeatedSubstringPattern('abcabcabcabc')) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/58.py: -------------------------------------------------------------------------------- 1 | # Length of Last Word 2 | 3 | class Solution: 4 | def lengthOfLastWord(self, s: str) -> int: 5 | words = s.split() 6 | return len(words[-1]) 7 | 8 | 9 | s = Solution() 10 | print(s.lengthOfLastWord("Hello World")) 11 | print(s.lengthOfLastWord(" fly me to the moon ")) 12 | print(s.lengthOfLastWord("luffy is still joyboy")) 13 | -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/66.py: -------------------------------------------------------------------------------- 1 | # Plus One 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def plusOne(self, digits: List[int]) -> List[int]: 7 | # integer = 0 8 | # for digit in digits: 9 | # integer = (integer * 10) + digit 10 | # integer += 1 11 | # 12 | # ans = [] 13 | # while integer > 0: 14 | # ans.insert(0, integer % 10) 15 | # integer = integer // 10 16 | # 17 | # return ans 18 | 19 | for i in reversed(range(len(digits))): 20 | if digits[i] == 9: 21 | digits[i] = 0 22 | else: 23 | digits[i] += 1 24 | return digits 25 | 26 | return [1] + digits 27 | 28 | 29 | s = Solution() 30 | print(s.plusOne([1, 2, 3])) 31 | print(s.plusOne([4, 3, 2, 1])) 32 | print(s.plusOne([9])) -------------------------------------------------------------------------------- /LeetCode/StudyPlan/ProgrammingSkills/709.py: -------------------------------------------------------------------------------- 1 | # To Lower Case 2 | 3 | class Solution: 4 | def toLowerCase(self, s: str) -> str: 5 | return s.lower() 6 | 7 | 8 | s = Solution() 9 | print(s.toLowerCase("Hello")) 10 | print(s.toLowerCase("here")) 11 | print(s.toLowerCase("LOVELY")) 12 | -------------------------------------------------------------------------------- /LeetCode/longestCommonPrefix.cpp: -------------------------------------------------------------------------------- 1 | // Longest Common Prefix 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class Solution { 8 | public: 9 | string longestCommonPrefix(vector& strs) { 10 | string prefix = ""; 11 | for(int i=0; i= strs[j].size()) { 16 | return prefix; 17 | } 18 | } 19 | prefix += strs[0][i]; 20 | } 21 | return prefix; 22 | } 23 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Problem Solving 2 | 3 | This is a repository where I store all my codes for practicing problem solving. 4 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1000.py: -------------------------------------------------------------------------------- 1 | # Hello World! 2 | import sys 3 | 4 | sys.stdout.write('Hello World!\n') 5 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1001.py: -------------------------------------------------------------------------------- 1 | # Extremely Basic 2 | import sys 3 | 4 | input = sys.stdin.read().strip().split() 5 | sys.stdout.write(f'X = {int(input[0]) + int(input[1])}\n') 6 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1002.py: -------------------------------------------------------------------------------- 1 | # Area of a Circle 2 | 3 | import sys 4 | 5 | n = 3.14159 6 | R = float(sys.stdin.read().strip()) 7 | sys.stdout.write(f'A={n * R * R:.4f}\n') 8 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1003.py: -------------------------------------------------------------------------------- 1 | # Simple Sum 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split() 6 | sys.stdout.write(f'SOMA = {int(input[0]) + int(input[1])}\n') 7 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1004.py: -------------------------------------------------------------------------------- 1 | # Simple Product 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split() 6 | sys.stdout.write(f'PROD = {int(input[0]) * int(input[1])}\n') 7 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1005.py: -------------------------------------------------------------------------------- 1 | # Average 1 2 | 3 | import sys 4 | 5 | A, B = map(float, sys.stdin.read().strip().split()) 6 | avg = ((A * 3.5) + (B * 7.5)) / (3.5 + 7.5) 7 | sys.stdout.write(f'MEDIA = {avg:.5f}\n') 8 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1006.py: -------------------------------------------------------------------------------- 1 | # Average 2 2 | 3 | import sys 4 | 5 | A, B, C = map(float, sys.stdin.read().strip().split()) 6 | 7 | avg = ((A * 2) + (B * 3) + (C * 5)) / (2 + 3 + 5) 8 | sys.stdout.write(f'MEDIA = {avg:.1f}\n') 9 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1007.py: -------------------------------------------------------------------------------- 1 | # Difference 2 | 3 | import sys 4 | 5 | a, b, c, d = map(int, sys.stdin.read().strip().split()) 6 | sys.stdout.write(f'DIFERENCA = {(a * b) - (c * d)}\n') 7 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1008.py: -------------------------------------------------------------------------------- 1 | # Salary 2 | 3 | import sys 4 | 5 | emp_no, work_hour, amount = map(float, sys.stdin.read().strip().split()) 6 | sys.stdout.write(f'NUMBER = {int(emp_no)}\nSALARY = U$ {(work_hour * amount):.2f}\n') 7 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1009.py: -------------------------------------------------------------------------------- 1 | # Salary with Bonus 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split() 6 | sys.stdout.write(f'TOTAL = R$ {float(input[1]) + (float(input[2]) * 0.15):.2f}\n') 7 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1010.py: -------------------------------------------------------------------------------- 1 | # Simple Calculate 2 | 3 | import sys 4 | 5 | input = sys.stdin.read().strip().split() 6 | 7 | prod1_unit, prod2_unit = int(input[1]), int(input[4]) 8 | prod1_price, prod2_price = float(input[2]), float(input[5]) 9 | 10 | sys.stdout.write(f'VALOR A PAGAR: R$ {((prod1_unit * prod1_price) + (prod2_unit * prod2_price)):.2f}\n') 11 | -------------------------------------------------------------------------------- /beecrowd/BEGINNER/1011.py: -------------------------------------------------------------------------------- 1 | # Sphere 2 | 3 | import sys 4 | pi = 3.14159 5 | 6 | R = float(sys.stdin.read().strip()) 7 | vol = (4/3) * pi * (R ** 3) 8 | 9 | sys.stdout.write(f'VOLUME = {vol:.3f}\n') 10 | 11 | -------------------------------------------------------------------------------- /faster_io_methods.py: -------------------------------------------------------------------------------- 1 | ### Faster Input and Output Methods in Python 2 | 3 | import sys 4 | 5 | ## Type 1: 6 | ## Taking integer as input 7 | 8 | # input = sys.stdin.readline().strip() 9 | # n = int(input) 10 | # sys.stdout.write(f'{n}, {type(n)}') 11 | # sys.stdout.flush() 12 | 13 | # n = int(sys.stdin.read().strip()) 14 | # sys.stdout.write(f'{n}\n') 15 | 16 | ## Type 2: 17 | ## Taking string as input 18 | 19 | # s = sys.stdin.readline().strip() 20 | # 21 | # sys.stdout.write(f'{s}, {type(s)}') 22 | # sys.stdout.flush() 23 | 24 | # s = sys.stdin.read().strip() 25 | # sys.stdout.write(f'{s}\n') 26 | 27 | ## Type 3: 28 | ## a b c 29 | ## 1 2 3 30 | 31 | # input = sys.stdin.readline().strip() 32 | # a, b, c = map(int, input.split()) 33 | # sys.stdout.write(f'{a}, {b}, {c}') 34 | 35 | # a, b, c = map(int, sys.stdin.read().strip().split()) 36 | # sys.stdout.write(f'{a} {b} {c}\n') 37 | 38 | ## Type 4: 39 | ## a b c d e... 40 | ## 1 2 3 4 5... 41 | 42 | # input = sys.stdin.readline().strip() 43 | # arr = list(map(int, input.split())) 44 | # sys.stdout.write(''.join(map(str, arr)) + '\n') 45 | # sys.stdout.write('\n'.join(map(str, arr)) + '\n') 46 | 47 | # arr = list(map(int, sys.stdin.read().strip().split())) 48 | # sys.stdout.write(' '.join(map(str, arr)) + '\n') 49 | 50 | ## Type 5: 51 | ## 5 52 | ## 1 2 3 4 5 53 | 54 | # n = int(sys.stdin.readline().strip()) 55 | # arr = list(map(int, sys.stdin.readline().strip().split())) 56 | # sys.stdout.write(f'{n}\n') 57 | # sys.stdout.write(' '.join(map(str, arr))) 58 | 59 | # input = sys.stdin.read().strip() 60 | # lines = input.split('\n') 61 | # n = int(lines[0].strip()) 62 | # nums = list(map(int, lines[1].strip().split())) 63 | # 64 | # sys.stdout.write(f'{n}\n') 65 | # sys.stdout.write(f' '.join(map(str, nums)) + '\n') 66 | 67 | ## Type 6: 68 | ## 3 -> no. of inputs 69 | ## 1 70 | ## 2 71 | ## 3 72 | 73 | # t = int(sys.stdin.readline().strip()) 74 | # sys.stdout.write(f'{t}') 75 | # for i in range(t): 76 | # n = int(sys.stdin.readline().strip()) 77 | # sys.stdout.write(f'{n}') 78 | # do operations... 79 | 80 | # input = sys.stdin.read().strip().split() 81 | # n = int(input[0]) 82 | # arr = list(map(int, input[1:n+1])) 83 | # sys.stdout.write(f'{n}\n') 84 | # sys.stdout.write(f' '.join(map(str, arr)) + '\n') 85 | 86 | ## Type 7: 87 | ## 2 88 | ## 3 89 | ## 1 2 3 90 | ## 5 91 | ## 1 2 3 4 5 92 | 93 | # t = int(sys.stdin.readline().strip()) 94 | # sys.stdout.write(f'{t}') 95 | # for i in range(t): 96 | # n = int(sys.stdin.readline().strip()) 97 | # sys.stdout.write(f'{n}') 98 | # arr = list(map(int, sys.stdin.readline().strip().split())) 99 | # sys.stdout.write(' '.join(map(str, arr))) 100 | # do operations... 101 | 102 | 103 | # input = sys.stdin.read().strip().split('\n') 104 | # t = int(input[0].strip()) 105 | # sys.stdout.write(f'{t}\n') 106 | # index = 1 107 | # for _ in range(t): 108 | # n = int(input[index].strip()) 109 | # index += 1 110 | # 111 | # arr = list(map(int, input[index].strip().split())) 112 | # index += 1 113 | # # do operations... 114 | # 115 | # sys.stdout.write(f'{n}\n') 116 | # sys.stdout.write(f' '.join(map(str, arr)) + '\n') 117 | 118 | ## Type 8: 119 | ## 4 120 | ## 1 2 3 4 121 | ## 5 6 7 8 122 | ## 9 10 11 12 123 | ## 13 14 15 16 124 | 125 | # t = int(sys.stdin.readline().strip()) 126 | # sys.stdout.write(f'{t}') 127 | # for i in range(t): 128 | # arr = list(map(int, sys.stdin.readline().strip().split())) 129 | # sys.stdout.write(' '.join(map(str, arr))) 130 | # do operations... 131 | 132 | # input = sys.stdin.read().strip().split('\n') 133 | # t = int(input[0].strip()) 134 | # sys.stdout.write(f'{t}\n') 135 | # 136 | # index = 1 137 | # for _ in range(t): 138 | # arr = list(map(int, input[index].strip().split())) 139 | # index += 1 140 | # # do operations... 141 | # 142 | # sys.stdout.write(f' '.join(map(str, arr)) + '\n') 143 | -------------------------------------------------------------------------------- /input_methods_for_cp.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": [ 6 | "# Input methods for competitive programming" 7 | ], 8 | "metadata": { 9 | "collapsed": false 10 | }, 11 | "id": "af244afa12b0bdad" 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "source": [ 16 | "## Type 1:\n", 17 | "Taking integer as input" 18 | ], 19 | "metadata": { 20 | "collapsed": false 21 | }, 22 | "id": "8e8a50d55d4243f5" 23 | }, 24 | { 25 | "cell_type": "code", 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "\n", 32 | "5\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "n = int(input())\n", 38 | "print(type(n))\n", 39 | "print(n)" 40 | ], 41 | "metadata": { 42 | "collapsed": false, 43 | "ExecuteTime": { 44 | "end_time": "2024-06-13T16:24:31.764259Z", 45 | "start_time": "2024-06-13T16:24:20.910321Z" 46 | } 47 | }, 48 | "id": "c65ff26262a2abb8", 49 | "execution_count": 1 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "source": [ 54 | "## Type 2:\n", 55 | "Taking string as input" 56 | ], 57 | "metadata": { 58 | "collapsed": false 59 | }, 60 | "id": "2e1bb7717033b29" 61 | }, 62 | { 63 | "cell_type": "code", 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "\n", 70 | "hello\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "s = input()\n", 76 | "print(type(s))\n", 77 | "print(s)" 78 | ], 79 | "metadata": { 80 | "collapsed": false, 81 | "ExecuteTime": { 82 | "end_time": "2024-06-13T16:24:40.902194Z", 83 | "start_time": "2024-06-13T16:24:35.111062Z" 84 | } 85 | }, 86 | "id": "9c3bc2a048bf4efe", 87 | "execution_count": 2 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "source": [ 92 | "# Type 3:\n", 93 | "```\n", 94 | "a b c\n", 95 | "1 2 3\n", 96 | "```" 97 | ], 98 | "metadata": { 99 | "collapsed": false 100 | }, 101 | "id": "13d96f406db795d1" 102 | }, 103 | { 104 | "cell_type": "code", 105 | "outputs": [ 106 | { 107 | "data": { 108 | "text/plain": "(10, 20, 30, int, int, int)" 109 | }, 110 | "execution_count": 3, 111 | "metadata": {}, 112 | "output_type": "execute_result" 113 | } 114 | ], 115 | "source": [ 116 | "a, b, c = map(int, input().split())\n", 117 | "a, b, c, type(a), type(b), type(c)" 118 | ], 119 | "metadata": { 120 | "collapsed": false, 121 | "ExecuteTime": { 122 | "end_time": "2024-06-13T16:25:02.662593Z", 123 | "start_time": "2024-06-13T16:24:56.784045Z" 124 | } 125 | }, 126 | "id": "84e531ee36bda556", 127 | "execution_count": 3 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "source": [ 132 | "## Type 4:\n", 133 | "```\n", 134 | "a b c d e...\n", 135 | "1 2 3 4 5...\n", 136 | "```" 137 | ], 138 | "metadata": { 139 | "collapsed": false 140 | }, 141 | "id": "c1e8f50aab98f6cc" 142 | }, 143 | { 144 | "cell_type": "code", 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" 149 | }, 150 | "execution_count": 4, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "arr = [int(i) for i in input().split()]\n", 157 | "arr" 158 | ], 159 | "metadata": { 160 | "collapsed": false, 161 | "ExecuteTime": { 162 | "end_time": "2024-06-13T16:25:24.321431Z", 163 | "start_time": "2024-06-13T16:25:09.868539Z" 164 | } 165 | }, 166 | "id": "4f14a3f965759ee2", 167 | "execution_count": 4 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "source": [ 172 | "## Type 5:\n", 173 | "```\n", 174 | "5\n", 175 | "1 2 3 4 5\n", 176 | "```" 177 | ], 178 | "metadata": { 179 | "collapsed": false 180 | }, 181 | "id": "c8928befff918aa0" 182 | }, 183 | { 184 | "cell_type": "code", 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "5\n", 191 | "[1, 2, 3, 4, 5]\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "n = int(input())\n", 197 | "arr = [int(i) for i in input().split()]\n", 198 | "print(n)\n", 199 | "print(arr)" 200 | ], 201 | "metadata": { 202 | "collapsed": false, 203 | "ExecuteTime": { 204 | "end_time": "2024-06-13T16:25:41.595604Z", 205 | "start_time": "2024-06-13T16:25:33.476363Z" 206 | } 207 | }, 208 | "id": "f6d8addc82b79a4b", 209 | "execution_count": 5 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "source": [ 214 | "## Type 6:\n", 215 | "```\n", 216 | "3 -> no. of inputs\n", 217 | "1\n", 218 | "2\n", 219 | "3\n", 220 | "```" 221 | ], 222 | "metadata": { 223 | "collapsed": false 224 | }, 225 | "id": "a6ad0d262e44ed2b" 226 | }, 227 | { 228 | "cell_type": "code", 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "3\n", 235 | "1\n", 236 | "2\n", 237 | "3\n" 238 | ] 239 | } 240 | ], 241 | "source": [ 242 | "n = int(input())\n", 243 | "print(n)\n", 244 | "for i in range(n):\n", 245 | " tc = int(input())\n", 246 | " print(tc)\n", 247 | " # ... do operations" 248 | ], 249 | "metadata": { 250 | "collapsed": false, 251 | "ExecuteTime": { 252 | "end_time": "2024-06-13T16:25:57.090539Z", 253 | "start_time": "2024-06-13T16:25:47.586968Z" 254 | } 255 | }, 256 | "id": "124a55f4985eccf6", 257 | "execution_count": 6 258 | }, 259 | { 260 | "cell_type": "markdown", 261 | "source": [ 262 | "## Type 7:\n", 263 | "```\n", 264 | "2\n", 265 | "3\n", 266 | "1 2 3\n", 267 | "5\n", 268 | "1 2 3 4 5\n", 269 | "```" 270 | ], 271 | "metadata": { 272 | "collapsed": false 273 | }, 274 | "id": "edce240bb0a2d977" 275 | }, 276 | { 277 | "cell_type": "code", 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "2\n", 284 | "3\n", 285 | "[1, 2, 3]\n", 286 | "5\n", 287 | "[1, 2, 3, 4, 5]\n" 288 | ] 289 | } 290 | ], 291 | "source": [ 292 | "t = int(input())\n", 293 | "print(t)\n", 294 | "for i in range(t):\n", 295 | " n = int(input())\n", 296 | " print(n)\n", 297 | " arr = [int(i) for i in input().split()]\n", 298 | " print(arr)\n", 299 | " # ... do operations" 300 | ], 301 | "metadata": { 302 | "collapsed": false, 303 | "ExecuteTime": { 304 | "end_time": "2024-06-13T16:26:17.338125Z", 305 | "start_time": "2024-06-13T16:26:03.012709Z" 306 | } 307 | }, 308 | "id": "452b3e74322dd1d8", 309 | "execution_count": 7 310 | }, 311 | { 312 | "cell_type": "markdown", 313 | "source": [ 314 | "## Type 8:\n", 315 | "```\n", 316 | "4\n", 317 | "1 2 3 4\n", 318 | "5 6 7 8\n", 319 | "9 10 11 12\n", 320 | "13 14 15 16\n", 321 | "```" 322 | ], 323 | "metadata": { 324 | "collapsed": false 325 | }, 326 | "id": "8760cd94d21bd82f" 327 | }, 328 | { 329 | "cell_type": "code", 330 | "outputs": [ 331 | { 332 | "name": "stdout", 333 | "output_type": "stream", 334 | "text": [ 335 | "4\n", 336 | "[1, 2, 3, 4]\n", 337 | "[5, 6, 7, 8]\n", 338 | "[9, 10, 11, 12]\n", 339 | "[13, 14, 15, 16]\n" 340 | ] 341 | } 342 | ], 343 | "source": [ 344 | "n = int(input())\n", 345 | "print(4)\n", 346 | "for i in range(n):\n", 347 | " arr = [int(i) for i in input().split()]\n", 348 | " print(arr)\n", 349 | " # ... do operations" 350 | ], 351 | "metadata": { 352 | "collapsed": false, 353 | "ExecuteTime": { 354 | "end_time": "2024-06-13T16:26:45.892937Z", 355 | "start_time": "2024-06-13T16:26:23.575737Z" 356 | } 357 | }, 358 | "id": "e736c6da5bf47164", 359 | "execution_count": 8 360 | } 361 | ], 362 | "metadata": { 363 | "kernelspec": { 364 | "display_name": "Python 3", 365 | "language": "python", 366 | "name": "python3" 367 | }, 368 | "language_info": { 369 | "codemirror_mode": { 370 | "name": "ipython", 371 | "version": 2 372 | }, 373 | "file_extension": ".py", 374 | "mimetype": "text/x-python", 375 | "name": "python", 376 | "nbconvert_exporter": "python", 377 | "pygments_lexer": "ipython2", 378 | "version": "2.7.6" 379 | } 380 | }, 381 | "nbformat": 4, 382 | "nbformat_minor": 5 383 | } 384 | --------------------------------------------------------------------------------