diff --git a/CODECHEF EASY/August Long One 2022 (AUG221B)/HLEQN.cpp b/CODECHEF EASY/August Long One 2022 (AUG221B)/HLEQN.cpp new file mode 100644 index 0000000..0e0c3f1 --- /dev/null +++ b/CODECHEF EASY/August Long One 2022 (AUG221B)/HLEQN.cpp @@ -0,0 +1,44 @@ +//Author: Akash Gautam (@geekblower) +//Date: 13-08-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i:a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(x) + + for(int i=1; i*i<=x; i++) { + if(((x - 2*i) % (i+2) == 0) && (x != 2*i)) { + display("YES") + return; + } + } + + display("NO") +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} \ No newline at end of file diff --git a/CODECHEF EASY/August Long One 2022 (AUG221B)/SMALLXOR.cpp b/CODECHEF EASY/August Long One 2022 (AUG221B)/SMALLXOR.cpp new file mode 100644 index 0000000..afb84d5 --- /dev/null +++ b/CODECHEF EASY/August Long One 2022 (AUG221B)/SMALLXOR.cpp @@ -0,0 +1,80 @@ +//Author: Akash Gautam (@geekblower) +//Date: 14-08-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +priority_queue> p,nul; +map> k; + +void otto() { + while(!p.empty()) { + cout<<-p.top().first<<' '; + p.pop(); + } + cout << endl; +} + +void solve() { + p = nul; + k.clear(); + + create(n) + create(x) + create(y) + + loop(i, 1, n+1, 1) { + create(t) + p.push({-t,i}); + } + + loop(i, 1, y+1, 1) { + pair _= {-((-p.top().first) ^ x), p.top().second}; + k[p.top().second].push_back (i); + + if(k[p.top().second].size() == 4) { + int s = k[p.top().second][3] - k[p.top().second][1]; + i += (y-i) / s*s; + + for(; i<=y; i++) { + pair t = {-((-p.top().first) ^ x), p.top().second}; + p.pop(); + p.push (t); + } + + otto(); + return; + } + + p.pop(); + p.push (_); + } + + otto(); +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} \ No newline at end of file diff --git a/CODECHEF EASY/August Long One 2022 (AUG221B)/TWOTRAINS.cpp b/CODECHEF EASY/August Long One 2022 (AUG221B)/TWOTRAINS.cpp new file mode 100644 index 0000000..96c6bf9 --- /dev/null +++ b/CODECHEF EASY/August Long One 2022 (AUG221B)/TWOTRAINS.cpp @@ -0,0 +1,62 @@ +//Author: Akash Gautam (@geekblower) +//Date: 13-08-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i:a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + + int *arr1 = new int[n]; + int *arr2 = new int[n]; + + arr1[0] = 0; + arr2[0] = 0; + + loop(i, 1, n, 1) { + cin>>arr1[i]; + } + + int sum = 0; + loop(i, 1, n, 1) { + sum += arr1[i]; + arr2[i] = arr1[i]; + arr1[i] = sum; + } + + loop(i, 0, n-1, 1) { + if(arr1[i+1] - arr2[i] > 0) { + arr2[i+1] = arr1[i+1] + arr2[i+1]; + } else { + arr2[i+1] = arr2[i] + arr2[i+1]; + } + } + + display(arr2[n-1]) +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} \ No newline at end of file diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/AUCTION.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/AUCTION.cpp new file mode 100644 index 0000000..35b6430 --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/AUCTION.cpp @@ -0,0 +1,44 @@ +//Author: Akash Gautam (@geekblower) +//Date: 09-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(a) + create(b) + create(c) + + if(a>b && a>c) + display("Alice") + else if(b>c) + display("Bob") + else + display("Charlie") +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/CHEFCAND.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/CHEFCAND.cpp new file mode 100644 index 0000000..c0e1285 --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/CHEFCAND.cpp @@ -0,0 +1,46 @@ +//Author: Akash Gautam (@geekblower) +//Date: 09-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + create(x) + + if(x>=n) + display("0") + else { + int tot = (n-x); + if(tot%4==0) + display(tot/4) + else + display(tot/4+1) + } +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/GAMEOFPILES1.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/GAMEOFPILES1.cpp new file mode 100644 index 0000000..31228cf --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/GAMEOFPILES1.cpp @@ -0,0 +1,46 @@ +//Author: Akash Gautam (@geekblower) +//Date: 10-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + def(arr, n) + + sort(arr, arr+n); + int odd = 0; + start_loop + odd = (arr[i]&1) ? odd+1 : odd; + + if(odd&1 || arr[0]==1) + display("CHEF") + else + display("CHEFINA") +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/KNIGHT2.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/KNIGHT2.cpp new file mode 100644 index 0000000..f0d621c --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/KNIGHT2.cpp @@ -0,0 +1,48 @@ +//Author: Akash Gautam (@geekblower) +//Date: 10-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(x1) + create(y1) + create(x2) + create(y2) + + int diff1 = abs(x1-x2); + int diff2 = abs(y1-y2); + + if(diff1&1 && diff2&1) + display("YES") + else if(diff1%2==0 && diff2%2==0) + display("YES") + else + display("NO") +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/PASSTHEEXAM.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/PASSTHEEXAM.cpp new file mode 100644 index 0000000..5e9e16a --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/PASSTHEEXAM.cpp @@ -0,0 +1,45 @@ +//Author: Akash Gautam (@geekblower) +//Date: 09-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(a) + create(b) + create(c) + + if(a>=10 && b>=10 && c>=10) { + if(a+b+c>=100) + display("PASS") + else + display("FAIL") + } else + display("FAIL") +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long One 2022 (JULY221D)/SLOWSOLN.cpp b/CODECHEF EASY/July Long One 2022 (JULY221D)/SLOWSOLN.cpp new file mode 100644 index 0000000..d4d73e8 --- /dev/null +++ b/CODECHEF EASY/July Long One 2022 (JULY221D)/SLOWSOLN.cpp @@ -0,0 +1,57 @@ +//Author: Akash Gautam (@geekblower) +//Date: 09-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(maxT) + create(maxN) + create(sumN) + + if(maxT*maxN <= sumN) { + display(maxN*maxN*maxT) + return; + } + + int totN=0, extra=0; + + while(sumN>maxN) { + sumN -= maxN; + totN++; + } + + if(sumN>0) + extra = sumN; + + int ans = totN * maxN * maxN; + ans += (extra*extra); + + display(ans) +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long Two 2022 (JULY222C)/BURGERS2.cpp b/CODECHEF EASY/July Long Two 2022 (JULY222C)/BURGERS2.cpp new file mode 100644 index 0000000..5c18451 --- /dev/null +++ b/CODECHEF EASY/July Long Two 2022 (JULY222C)/BURGERS2.cpp @@ -0,0 +1,59 @@ +//Author: Akash Gautam (@geekblower) +//Date: 23-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(x) + create(y) + create(n) + create(r) + + if(r < n*x) { + display("-1") + return; + } + + if(r >= n*y) { + display("0 "< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + def(arr,n) + + int index=-1, element=-1; + + loop(i, 0, n-1, 1) { + if(arr[i] > arr[i+1]) { + index = i+1; + element = arr[index]; + break; + } + } + + if(index==-1 || index==n-1) { + display("YES") + return; + } + + int leftMaximum; + loop(i, 0, index, 1) { + if(arr[i] > element) { + leftMaximum = arr[i]; + break; + } + } + + int rightMaximum = arr[index-1]; + int i; + + for(i=index+1; i= rightMaximum) + rightMaximum = arr[i]; + else if(arr[i]<=leftMaximum && arr[i]>=element) + element = arr[i]; + else { + display("NO") + break; + } + } + + if(i==n) + display("YES") + +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long Two 2022 (JULY222C)/DIF_GCD.cpp b/CODECHEF EASY/July Long Two 2022 (JULY222C)/DIF_GCD.cpp new file mode 100644 index 0000000..4033c83 --- /dev/null +++ b/CODECHEF EASY/July Long Two 2022 (JULY222C)/DIF_GCD.cpp @@ -0,0 +1,57 @@ +//Author: Akash Gautam (@geekblower) +//Date: 23-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + create(m) + + if(n==1) { + display("1 "<= maximum) { + maximum = abs(b-i); + x = i; + y = b; + } + } + + display(x<<" "< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(a) + create(b) + create(n) + + if(a==b || a%b==0) { + display("-1") + return; + } + + n += (n%a) ? (a-(n%a)) : 0; + + while(n%b==0) + n += a; + + display(n) +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long Two 2022 (JULY222C)/OFFICE.cpp b/CODECHEF EASY/July Long Two 2022 (JULY222C)/OFFICE.cpp new file mode 100644 index 0000000..260d298 --- /dev/null +++ b/CODECHEF EASY/July Long Two 2022 (JULY222C)/OFFICE.cpp @@ -0,0 +1,38 @@ +//Author: Akash Gautam (@geekblower) +//Date: 23-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(x) + create(y) + + display(x*4+y) +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/July Long Two 2022 (JULY222C)/SUMOFPROD1.cpp b/CODECHEF EASY/July Long Two 2022 (JULY222C)/SUMOFPROD1.cpp new file mode 100644 index 0000000..89fea0a --- /dev/null +++ b/CODECHEF EASY/July Long Two 2022 (JULY222C)/SUMOFPROD1.cpp @@ -0,0 +1,50 @@ +//Author: Akash Gautam (@geekblower) +//Date: 25-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + def(arr,n) + + int ans = 0; + + start_loop { + int count = 0; + while(arr[i]==1 && i +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int a, b; + cin>>a>>b; + int temp = (b-a)%3; + if(temp==2) + cout<<"NO\n"; + else + cout<<"YES\n"; + } + + return 0; +} diff --git a/CODECHEF EASY/June Long One 2022 (JUNE221D)/CHAIRS_.cpp b/CODECHEF EASY/June Long One 2022 (JUNE221D)/CHAIRS_.cpp new file mode 100644 index 0000000..ed09af3 --- /dev/null +++ b/CODECHEF EASY/June Long One 2022 (JUNE221D)/CHAIRS_.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int x, y; + cin>>x>>y; + if(x>y) + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int a, b, n, count=0; + cin>>a>>b; + n = abs(a-b); + for(int i=1; i<=sqrt(n); i++) { + if(n%i == 0) { + if(n/i == i) + count++; + else + count += 2; + } + } + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n; + cin>>n; + int *ans = new int[n]; + int temp = n; + for(int i=n-1; i>=0; i-=2) + ans[i] = temp--; + for(int i=n-2, c=1; i>=0; i-=2, c++) + ans[i] = c; + for(int i=0; i +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n, step=0; + string str1, str2; + cin>>n; + cin>>str1>>str2; + for(int i=0; i +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n, x; + cin>>n>>x; + int temp = n/6; + if(n > temp*6) + temp += 1; + cout< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(a.begin(),a.end()) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) inta[n];loop(i,0,n){cin>>a[i];} +#define print(a) for(auto i : a){cout<9 && score!=10) { + cout<<-1< 10) + cout<<-1< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) int a[n];loop(i,0,n){cin>>a[i];} +#define print(a) for(auto i : a){cout<>dna; + start_loop { + switch(dna[i]) { + case 'A': + dna[i] = 'T'; + break; + case 'T': + dna[i] = 'A'; + break; + case 'C': + dna[i] = 'G'; + break; + case 'G': + dna[i] = 'C'; + break; + } + } + cout< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(a.begin(),a.end()) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) inta[n];loop(i,0,n){cin>>a[i];} +#define print(a) for(auto i : a){cout< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) int a[n];loop(i,0,n){cin>>a[i];} +#define print(a) for(auto i : a){cout< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout< arr[i+1]) { + if((arr[i]+arr[i+1]) > x) { + flag = false; + break; + } else { + swap(arr[i], arr[i+1]); + } + } + } + + if(flag) + cout<<"YES"< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;ib;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,0,n,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout< 1) + ans++; + } + + display(ans) +} + +int32_t main() { + GEEKBLOWER + TEST_CASES + SOLUTION +} diff --git a/CODECHEF EASY/May Long One 2022 (MAY221D)/F1RULE.cpp b/CODECHEF EASY/May Long One 2022 (MAY221D)/F1RULE.cpp new file mode 100644 index 0000000..3b23b08 --- /dev/null +++ b/CODECHEF EASY/May Long One 2022 (MAY221D)/F1RULE.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int x,y; + cin>>x>>y; + + if(y <= (x*1.07)) + cout<<"YES"< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int x,y; + cin>>x>>y; + + if(x==y && (x>0 && y>0)) + cout<<"YES"< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n, x, y, count=0; + cin>>n>>x>>y; + + // Adding under-attack horizontal and vertical elements + count = 2*(n-1); + + // Adding under-attack north-east elements + if(x-1>0 && n-y>0) + count += min(x-1, n-y); + + // Adding under-attack south-east elements + if(n-x>0 && n-y>0) + count += min(n-x, n-y); + + // Adding under-attack south-west elements + if(n-x>0 && y-1>0) + count += min(n-x, y-1); + + // Adding under-attack north-west elements + if(x-1>0 && y-1>0) + count += min(x-1, y-1); + + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n; + cin>>n; + + // Since after spending 20%, 20% and 30%, the remaining profit is 30% -> 15 coins per sale + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n, a[1000]; + cin>>n; + + for(int i=0; i>a[i]; + + int temp = n-1; + + while(a[temp] == 0) + temp--; + + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int n, a, b, c, d; + cin>>n; + cin>>a>>b>>c>>d; + + if(a>=b && a>=c && a>=d && a<=n) + cout<=a && b>=c && b>=d && b<=n) + cout<=a && c>=b && c>=d && c<=n) + cout< +using namespace std; + +int main() { + int a[4], count=0; + + for(int i=0; i<4; i++) { + cin>>a[i]; + if(a[i] >= 10) + count++; + } + cout< +using namespace std; + +int main() { + int t; + cin>>t; + + while(t--) { + int x, y; + cin>>x>>y; + cout<<(x*10)+(y*90)< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + int count = 0; + + while(n) { + if(n%10==4 || n%10==7) + count++; + n /= 10; + } + + if(count==4 || count==7) + display("YES") + else + display("NO") +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/112A - Petya and Strings.cpp b/CodeForces Problems/112A - Petya and Strings.cpp new file mode 100644 index 0000000..94af7ae --- /dev/null +++ b/CodeForces Problems/112A - Petya and Strings.cpp @@ -0,0 +1,45 @@ +//Author: Akash Gautam (@geekblower) +//Date: 25-06-2022 +#include +#include +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLVE solve(); return 0; +#define VI vector +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(a.begin(),a.end()) +#define loop(i,a,b,c) for(int i=a;i>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>str1>>str2; + int n = str1.length(); + start_loop { + char ch1 = toupper(str1[i]); + char ch2 = toupper(str2[i]); + if(ch1 > ch2) + return 1; + if(ch1 < ch2) + return -1; + } + return 0; +} + +int32_t main() { + GEEKBLOWER + int n = solve(); + cout< +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + int total=0, ans=0; + + start_loop { + create(a) + create(b) + int temp = total; + + total -= a; + total += b; + + ans = max(total, ans); + } + + display(ans) +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/136A - Presents.cpp b/CodeForces Problems/136A - Presents.cpp new file mode 100644 index 0000000..86de387 --- /dev/null +++ b/CodeForces Problems/136A - Presents.cpp @@ -0,0 +1,46 @@ +//Author: Akash Gautam (@geekblower) +//Date: 18-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + def(arr,n) + + int *ans = new int[n]; + + start_loop { + int x = arr[i]; + ans[x-1] = i+1; + } + + start_loop + cout< +#include +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>str1>>str2>>str3; + mystr = str1 + str2; + + SORT(mystr) + SORT(str3) + + if(str3==mystr) + display("YES") + else + display("NO") +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/144A - Arrival of the General.cpp b/CodeForces Problems/144A - Arrival of the General.cpp new file mode 100644 index 0000000..93dd410 --- /dev/null +++ b/CodeForces Problems/144A - Arrival of the General.cpp @@ -0,0 +1,54 @@ +//Author: Akash Gautam (@geekblower) +//Date: 20-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + create(n) + def(arr,n) + + int maximum=arr[0], minimum=arr[0]; + start_loop { + maximum = max(maximum, arr[i]); + minimum = min(minimum, arr[i]); + } + + int maxIndex=-1, minIndex=-1; + start_loop { + if(maxIndex==-1 && arr[i]==maximum) + maxIndex = i; + if(arr[i]==minimum) + minIndex = i; + } + + if(minIndex>maxIndex) + display(maxIndex + n - minIndex - 1) + else + display(maxIndex + n - minIndex - 2) +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/148A - Insomnia cure.cpp b/CodeForces Problems/148A - Insomnia cure.cpp new file mode 100644 index 0000000..85f5dc1 --- /dev/null +++ b/CodeForces Problems/148A - Insomnia cure.cpp @@ -0,0 +1,44 @@ +//Author: Akash Gautam (@geekblower) +//Date: 29-06-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)); +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout< +using namespace std; + +int main() { + int w; + cin>>w; + + if(w%2 || w==2) + cout<<"NO"; + else + cout<<"YES"; + + return 0; +} \ No newline at end of file diff --git a/CodeForces Problems/50A - Domino piling.cpp b/CodeForces Problems/50A - Domino piling.cpp new file mode 100644 index 0000000..cd201c1 --- /dev/null +++ b/CodeForces Problems/50A - Domino piling.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; + +int main() { + int m, n; + cin>>m>>n; + cout<<(m*n)/2; + return 0; +} \ No newline at end of file diff --git a/CodeForces Problems/59A - Word.cpp b/CodeForces Problems/59A - Word.cpp new file mode 100644 index 0000000..986b629 --- /dev/null +++ b/CodeForces Problems/59A - Word.cpp @@ -0,0 +1,56 @@ +//Author: Akash Gautam (@geekblower) +//Date: 28-06-2022 +#include +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>str; + int n = str.length(); + + // Two variables to count the number of uppercase and lowercase alphabets + int up=0, lo=0; + + // Counting up & lo + start_loop { + if(isupper(str[i])) + up++; + else + lo++; + } + + if(up>lo) { + start_loop + str[i] = toupper(str[i]); + } else { + start_loop + str[i] = tolower(str[i]); + } + + display(str) +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/61A - Ultra-Fast Mathematician.cpp b/CodeForces Problems/61A - Ultra-Fast Mathematician.cpp new file mode 100644 index 0000000..99f861a --- /dev/null +++ b/CodeForces Problems/61A - Ultra-Fast Mathematician.cpp @@ -0,0 +1,47 @@ +//Author: Akash Gautam (@geekblower) +//Date: 23-07-2022 +#include +using namespace std; + +#define endl '\n' +#define GEEKBLOWER ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define int long long int +#define TEST_CASES create(t);while(t--) +#define SOLUTION solve(); return 0; +#define display(n) cout< +#define PB push_back +#define ALL(a) a.begin(),a.end() +#define SORT(a) sort(ALL(a)) +#define loop(i,a,b,c) for(int i=a;i=b;i-=c) +#define start_loop loop(i,0,n,1) +#define start_revloop revloop(i,n,0,1) +#define create(n) int n;cin>>n; +#define def(a,n) int a[n];start_loop cin>>a[i]; +#define print(a) for(auto i : a){cout<>x;a.PB(x);} +inline int GCD(int a,int b){return !b?a:GCD(b,a%b);} +const int MOD = 1000000007; + +void solve() { + string str1, str2; + cin>>str1>>str2; + + string ans; + int n = str1.length(); + + start_loop { + if(str1[i] == str2[i]) + ans.PB ('0'); + else + ans.PB ('1'); + } + + display(ans) +} + +int32_t main() { + GEEKBLOWER + SOLUTION +} diff --git a/CodeForces Problems/71A - Way Too Long Words.cpp b/CodeForces Problems/71A - Way Too Long Words.cpp new file mode 100644 index 0000000..ede4603 --- /dev/null +++ b/CodeForces Problems/71A - Way Too Long Words.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main() { + int n; + cin>>n; + + while(n--) { + string str; + cin>>str; + int size = str.length(); + if(size>10) { + int i=1; + while(str[i] != '\0') + i++; + cout<