Codeforces : From Newbie to Expert (900-Rated)

so ... I will be sharing all solutions here (recent solutions at the top, or find by ctrl+f)

                                


900 Rated Problems Link : ProblemSet

Video Explanations : Check Here



100. Little Elephant and Rozdil

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. ll n; cin>>n;
  7. pair<ll,ll> a[n];
  8. for(int i=1; i<=n; i++){
  9. cin>>a[i].first;
  10. a[i].second = i;
  11. }
  12. sort(a+1,a+n+1);
  13. if(a[1].first==a[2].first) cout<<"Still Rozdil";
  14. else cout<<a[1].second;
  15. }


99. BAN BAN

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. cout<<n/2 + n%2<<endl;
  8. int l=1, r=3*n;
  9. while(l<r){
  10. cout<<l<<" "<<r<<endl;
  11. l += 3;
  12. r -= 3;
  13. }
  14. }
  15. }


98. Minimize Inversions

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. vector<int> p(n), q(n);
  9. for(int i=0; i<n; i++) cin>>p[i];
  10. for(int i=0; i<n; i++) cin>>q[i];
  11. vector<vector<int>> inv;
  12. for(int i=0; i<n; i++)
  13. inv.push_back({p[i]-1+q[i]-1, p[i], q[i]});
  14. sort(inv.begin(), inv.end());
  15. for(auto i: inv) cout<<i[1]<<" ";
  16. cout<<endl;
  17. for(auto i: inv) cout<<i[2]<<" ";
  18. cout<<endl;
  19. }
  20. }


97. Burenka Plays with Fractions

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll a, b, c, d;
  8. cin>>a>>b>>c>>d;
  9. ll x = a*d, y = b*c;
  10. if(x==y) cout<<0<<endl;
  11. else if(x==0 || y==0 || x%y==0 || y%x==0) cout<<1<<endl;
  12. else cout<<2<<endl;
  13. }
  14. }



96. Also Try Minecraft

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. int n, m; cin>>n>>m;
  7. ll a[n],s1[n], s2[n];
  8.  
  9. for(int i=1; i<=n; i++) cin>>a[i];
  10. for(int i=1; i<=n; i++){
  11. s1[i]=s1[i-1];
  12. if(a[i]<a[i-1]) s1[i]+=a[i-1]-a[i];
  13. }
  14. for(int i=n; i>=1; i--){
  15. s2[i]=s2[i+1];
  16. if(a[i+1]>a[i]) s2[i]+=a[i+1]-a[i];
  17. }
  18. while(m--){
  19. int s,t;
  20. cin>>s>>t;
  21. if(s<t) cout<<s1[t]-s1[s]<<endl;
  22. else cout<<s2[t]-s2[s]<<endl;
  23. }
  24. }



95. Cookies

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int c, sum=0, even=0, odd=0;
  6. for(int i=0; i<n; i++) {
  7. cin>>c;
  8. sum+=c;
  9. if(c%2==0) even++;
  10. else odd++;
  11. }
  12. if(sum%2==0) cout<<even;
  13. else cout<<odd;
  14. }


94. Contest

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int score(int p, int t){
  4. return max(3*p/10, p - p*t/250);
  5. }
  6.  
  7. int main(){
  8. int a,b,c,d;
  9. cin>>a>>b>>c>>d;
  10. int Misha = score(a,c), Vasya=score(b,d);
  11. if(Misha==Vasya) cout<<"Tie";
  12. else if(Misha<Vasya) cout<<"Vasya";
  13. else cout<<"Misha";
  14. return 0;
  15. }

                                                              OR

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int a,b,c,d;
  5. cin>>a>>b>>c>>d;
  6. a = max(3*a/10, a - a*c/250);
  7. b = max(3*b/10, b - b*d/250);
  8. if(a == b) cout<<"Tie";
  9. else if(a<b) cout<<"Vasya";
  10. else cout<<"Misha";
  11. return 0;
  12. }


93. Hossam and Combinatorics

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. int t; cin>>t;
  7. while(t--){
  8. ll n; cin>>n;
  9. ll a[n];
  10. map<ll, ll> m;
  11.  
  12. for(int i=0; i<n; i++) {
  13. cin>>a[i];
  14. m[a[i]]++;
  15. }
  16. sort(a,a+n);
  17. if(m.size()==1) cout<<n*(n-1)<<endl;
  18. else cout<<2*m[a[0]]*m[a[n-1]]<<endl;
  19. }
  20.  
  21. }


92. Quick Sort

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. ll t; cin>>t;
  6. while(t--){
  7. int n,k; cin>>n>>k;
  8. vector<int> a(n);
  9. for(int i=0; i<n; i++) cin>>a[i];
  10. int num=1, total=0;
  11. for(int j=0; j<n; j++)
  12. if(a[j]==num) num++;
  13. else total++;
  14. int ans = (total+k-1)/k;
  15. cout<<ans<<endl;
  16. }
  17.  
  18. }


91. Mocha and Red and Blue

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. ll t; cin>>t;
  6. while(t--){
  7. int n, pos=0; string s; cin>>n>>s;
  8. for(int i=1; i<n; i++)
  9. if(s[i]=='?')
  10. if(s[i-1]=='R') s[i]='B';
  11. else if(s[i-1]=='B') s[i]='R';
  12. for(int i=n-2; i>=0; i--)
  13. if(s[i]=='?')
  14. if(s[i+1]=='R') s[i]='B';
  15. else if(s[i+1]=='B') s[i]='R';
  16. if(s[0]=='?')
  17. for(int i=0; i<n; i++)
  18. if(i%2) s[i]='B';
  19. else s[i]='R';
  20. cout<<s<<endl;
  21. }
  22.  
  23.  
  24. }



90. Rudolf and the Ugly String


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; string s;
  8. cin>>n>>s;
  9. int cnt=0;
  10. for(int i=0; i<n; i++){
  11. if(s.substr(i,3) == "map" || s.substr(i,3)=="pie") cnt++;
  12. if(s.substr(i,5) == "mapie") cnt--;
  13. }
  14. cout<<cnt<<endl;
  15. }
  16. }

                                                      


89. Mark the Dust Sweeper

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void solve(){
  6. int n; cin>>n;
  7. ll a[n], pos=-1, sum=0, zero=0;
  8. for(int i=0; i<n; i++) cin>>a[i];
  9.  
  10. for(int i=0; i<n-1; i++) if(a[i]!=0) {pos=i; break;}
  11.  
  12. if(pos==-1) { cout<<0<<endl; return; }
  13.  
  14. for(int i=pos; i<n-1; i++){
  15. sum += a[i];
  16. if(a[i]==0) zero++;
  17. }
  18. cout<<sum+zero<<endl;
  19. }
  20.  
  21. int main(){
  22. int t; cin>>t;
  23. while(t--){
  24. solve();
  25. }
  26. }


88. Delete from the Left


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. string a, b;
  6. cin>>a>>b;
  7. int ans = a.size() + b.size();
  8. while(a.size() && b.size() && a.back() == b.back()){
  9. ans = ans - 2;
  10. a.pop_back();
  11. b.pop_back();
  12. }
  13. cout<<ans;
  14. return 0;
  15. }



87. AB Balance

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. string s; cin>>s;
  7. s[s.size()-1] = s[0];
  8. cout<<s<<endl;
  9. }
  10. }


86. GCD Problem

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5. int n; cin>>n;
  6. if(n%2==0) cout<<"2 "<<(n-3)<<" 1\n";
  7. else{
  8. int mid = (n-1)/2;
  9. if(mid%2==0) cout<<mid-1<<" "<<mid+1<<" "<<1<<'\n';
  10. else cout<<mid-2<<" "<<mid+2<<" "<<1<<endl;
  11. }
  12. }
  13.  
  14. int main(){
  15. int t; cin>>t;
  16. while(t--) solve();
  17. }


85. Display The Number

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. if(n%2==1) {cout<<"7"; n-=3;}
  8. for(int i=0; i<n/2; i++) cout<<"1";
  9. cout<<endl;
  10. }
  11. }


84. Duff and Meat

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int a, p, p_min = INT_MAX, sum=0;
  6. for(int i=0; i<n; i++){
  7. cin>>a>>p;
  8. p_min = min(p, p_min);
  9. sum += a * p_min;
  10. }
  11. cout<<sum;
  12. }


83. Three Indices

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. vector<int> a(n);
  9. for(auto &x : a) cin>>x;
  10. int flag=0;
  11. for(int i=1;i<n-1;i++){
  12. if(a[i-1] < a[i] and a[i] > a[i+1]){
  13. flag = 1;
  14. cout<<"YES\n"<<i<<" "<<i+1<<" "<<i+2<<endl;
  15. break;
  16. }
  17. }
  18. if(flag==0) cout<<"NO\n";
  19.  
  20. }
  21. }


82. Longest Divisors Interval

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll n, i=1; cin>>n;
  8. while(n%i==0) i++;
  9. cout<<i-1<<endl;
  10. }
  11. }


81. Customising the Track

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. int t; cin>>t;
  8. while(t--){
  9. int n,a; cin>>n;
  10. ll sum=0;
  11. for(int i=0; i<n; i++){
  12. cin>>a;
  13. sum+=a;
  14. }
  15. ll r = sum % n;
  16. cout<<r*(n-r)<<endl;
  17. }
  18. }



80. Good Arrays

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. int t; cin>>t;
  8. while(t--){
  9. int n; cin>>n;
  10. vector<ll> a(n);
  11. ll sum = 0;
  12. for(int i=0; i<n; i++) cin>>a[i], sum+=a[i];
  13.  
  14. for(int i=0; i<n; i++) {
  15. if(a[i]==1) sum -= 2;
  16. else sum -= 1;
  17. }
  18. if(sum<0 || n==1) cout<<"NO\n";
  19. else cout<<"YES\n";
  20. }
  21. }



79. Three Threadlets

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll a, b, c; cin>>a>>b>>c;
  8. //to get min value in a
  9. if(b<a) swap(a,b);
  10. if(c<a) swap(a,c);
  11. //3 cases
  12. if(a==b && b==c) cout<<"YES\n";
  13. else if(b%a==0 && c%a==0 && (b/a-1)+ (c/a-1)<=3)
  14. cout<<"YES\n";
  15.  
  16. else cout<<"NO\n";
  17. }
  18. }



78. Cubes Sorting

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. int a[n];
  9. bool flag = 0;
  10.  
  11. for(int i=0; i<n; i++) cin>>a[i];
  12.  
  13. for(int i=1; i<n; i++){
  14. if(a[i]>=a[i-1]) {
  15. flag=1; break;
  16. }
  17. }
  18.  
  19. cout<<(flag?"YES":"NO")<<endl;
  20. }
  21. }



77. MKnez's ConstructiveForces Task

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void solve(){
  6. int n; cin>>n;
  7. if(n==3) {cout<<"NO"<<endl; return;}
  8. cout<<"YES"<<endl;
  9.  
  10. if(n%2==0){
  11. for(int i=0; i<n; i+=2) cout<<"1 -1 ";
  12. cout<<endl;
  13. } else {
  14. int k = n/2;
  15. for(int i=0; i<n-1; i+=2)
  16. cout<<k-1<<' '<<-k<<' ';
  17. cout<<k-1<<endl;
  18. }
  19.  
  20. }
  21.  
  22. int main(){
  23. int t; cin>>t;
  24. while(t--){
  25. solve();
  26. }
  27. }



76. Prime Subtraction

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. int t; cin>>t;
  7. while(t--){
  8. ll x,y; cin>>x>>y;
  9. if(x-y == 1) cout<<"NO"<<endl;
  10. else cout<<"YES"<<endl;
  11. }
  12. }



75. Alarm Clock

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. int t; cin>>t;
  7. while(t--){
  8. ll a, b, c, d; cin>>a>>b>>c>>d;
  9. ll sleep = -1;
  10. if(b>=a) sleep = b;
  11. else {
  12. if(d>=c) sleep=-1;
  13. else sleep = b + c*((a-b+c-d-1)/(c-d));
  14. }
  15. cout<<sleep<<endl;
  16. }
  17. }



74. Chips Moving

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int odd=0;
  6. for(int i=0; i<n; i++){
  7. int x; cin>>x;
  8. odd += x & 1;
  9. }
  10. cout<<min(odd, n-odd)<<endl;
  11. }



73. Maximums

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int x=0;
  6. for(int i=0; i<n; i++){
  7. int b; cin>>b;
  8. int a = b + x;
  9. x = max(x,a);
  10. cout<<a<<' ';
  11. }
  12. cout<<endl;
  13. }



72. Chemistry

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n, k; cin>>n>>k;
  7. string s; cin>>s;
  8. map<char,int> m;
  9. for(int i=0; i<n; i++) m[s[i]]++;
  10.  
  11. int count=0;
  12. for(int i='a'; i<='z'; i++)
  13. if(m[i]%2) count++;
  14. if(count>k+1) cout<<"NO"<<endl;
  15. else cout<<"YES"<<endl;
  16. }
  17. }



71. Following the String

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. map<char, int> freq;
  8. string s = "";
  9. for(int i=0; i<n; i++){
  10. int a; cin>>a;
  11. for(char c='a'; c<='z'; c++)
  12. if(freq[c]==a){
  13. s.push_back(c);
  14. freq[c]++;
  15. break;
  16. }
  17. }
  18. cout<<s<<endl;
  19. }
  20.  
  21. }



70. Make It Increasing

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. vector<int> a(n);
  8. for(auto &i: a) cin>>i;
  9. int ans=0, flag=1;
  10. for(int i=n-2; i>=0; i--){
  11. while(a[i]>=a[i+1] && a[i]>0){
  12. a[i]/=2;
  13. ans++;
  14. }
  15. if(a[i]==a[i+1])
  16. {cout<<-1<<endl; flag=0; break;}
  17. }
  18. if(flag) cout<<ans<<endl;
  19. }
  20. }


69. Long Comparison

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. double a, b, c, d;
  8. cin>>a>>b>>c>>d;
  9. double x = log10(a) + b, y = log10(c) + d;
  10. if(abs(x - y) <= 1e-7) cout<<"="<<endl;
  11. else if(x>y) cout<<">"<<endl;
  12. else cout<<"<"<<endl;
  13. }
  14. }


68. Odd Grasshopper

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll x, n; cin>>x>>n;
  8. ll ans = x;
  9. if(x%2==0){
  10. if(n%4==1) ans-=n;
  11. else if(n%4==2) ans++;
  12. else if(n%4==3) ans += n+1;
  13. }
  14. else{
  15. if(n%4==1) ans+=n;
  16. else if(n%4==2) ans--;
  17. else if(n%4==3) ans -= n+1;
  18. }
  19. cout<<ans<<endl;
  20. }
  21. }


67. Strange Partition

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. long long int n, x, y, _max=0, _min=0;
  7. cin>>n>>x;
  8. for(int i=0; i<n; i++){
  9. cin>>y;
  10. _min += y;
  11. _max += (y + x - 1)/x;
  12. }
  13. cout<<(_min + x - 1)/x<<" "<<_max<<endl;
  14. }
  15. }


66. Wizard of Orz

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. string s = "989";
  8. if(n==1) cout<<"9"<<endl;
  9. if(n==2) cout<<"98"<<endl;
  10. if(n>=3){
  11. cout<<s;
  12. for(int i=0; i<n-3; i++)
  13. cout<<i%10;
  14. cout<<endl;
  15. }
  16. }
  17. }



65. Tricky Sum

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. long long int n, s, pow2=1;
  7. cin>>n;
  8. s = n*(n+1)/2;
  9. while(pow2<=n)
  10. s -= pow2*2, pow2 *= 2;
  11. cout<<s<<endl;
  12. }
  13. }



64. Permutation Sort

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t;
  6. cin >> t;
  7.  
  8. while(t--){
  9. int n;
  10. cin >> n;
  11.  
  12. vector<int> a(n);
  13. for(int &i : a)
  14. cin >> i;
  15.  
  16. int ans = 2;
  17.  
  18. if (is_sorted(a.begin(), a.end()))
  19. ans = 0;
  20. else if (a[0] == 1 || a[n - 1] == n)
  21. ans = 1;
  22. else if (a[0] == n && a[n - 1] == 1)
  23. ans = 3;
  24.  
  25. cout << ans << endl;
  26. }
  27. return 0;
  28. }


63. Make it Divisible by 25

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. string s; cin>>s;
  7. int n = s.size();
  8. int ans=INT_MAX;
  9. for(int i=0; i<n; i++){
  10. for(int j=i+1; j<n; j++){
  11. int no = s[i]-'0';
  12. no = no*10 + s[j]-'0';
  13. if(no%25==0)
  14. ans = min(ans, j-i-1+n-j-1);
  15. }
  16. }
  17. cout<<ans<<endl;
  18. }
  19. }



62. Hexadecimal's theorem

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. cout<<n<<" "<<0<<" "<<0<<endl;
  6. }


61. Sending Messages

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. long long int n, f, a, b, temp=0;
  7. cin>>n>>f>>a>>b;
  8. for(int i=0; i<n; i++){
  9. long long int val;
  10. cin>>val;
  11. f -= min((val-temp)*a,b); //per second cost = a
  12. temp = val; //restart cost = b
  13. }
  14. cout<<(f>0?"YES":"NO")<<endl;
  15. }
  16. }



60. Unnatural Language Processing

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t,n;
  5. cin>>t;
  6. while(t--){
  7. string s; cin>>n>>s;
  8. cout<<s[0];
  9. for(int i=1; i<n; i++){
  10. if((s[i+1]=='a'|| s[i+1]=='e'))
  11. cout<<".";
  12. cout<<s[i];
  13. }
  14. cout<<endl;
  15. }
  16. }



59. Devu, the Singer and Churu, the Joker

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, d, sum = 0;
  5. cin>>n>>d;
  6. int a[n];
  7. for(int i=0; i<n; i++) cin>>a[i], sum+=a[i];
  8. if(sum + (n-1)*10 > d) cout<<-1<<endl;
  9. else cout<< (d-sum)/5<<endl;
  10. }



58. Shifting Stacks

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. vector<int> a(n);
  8. for(auto &i:a) cin>>i;
  9. long long sum = 0, req = 0, flag=0;
  10. for(int i=0; i<n; i++){
  11. req += i;
  12. sum += a[i];
  13. if(sum<req) flag=1;
  14. }
  15. cout<<(flag==0?"YES\n":"NO\n");
  16. }
  17. }



57. Comparison String

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. string s; cin>>s;
  9. int ans = 1, cnt = 1;
  10.  
  11. for(int i=1; i<n; i++){
  12. if(s[i]!=s[i-1]) cnt=1;
  13. else cnt++;
  14. ans = max(ans, cnt);
  15. }
  16. cout<<ans+1<<endl;
  17. }
  18. }



56. Restore the Weather

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n,k; cin>>n>>k;
  7. int ans[n], b[n];
  8. pair<int, int> a[n];
  9. for(int i=1; i<=n; i++){
  10. cin>>a[i].first;
  11. a[i].second = i;
  12. }
  13. for(int i=1; i<=n; i++)
  14. cin>>b[i];
  15. sort(a+1, a+n+1);
  16. sort(b+1, b+n+1);
  17. for(int i=1; i<=n; i++)
  18. ans[a[i].second] = b[i];
  19. for(int i=1; i<=n;i++)
  20. cout<<ans[i]<<" ";
  21. cout<<endl;
  22. }
  23. }



55. Promo

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n,q; cin>>n>>q;
  5. long long int a[n],b[n];
  6. for(int i=1; i<=n; i++) cin>>a[i];
  7. sort(a+1,a+n+1,greater<int>());
  8.  
  9. for(int i=1; i<=n; i++)
  10. b[i]=b[i-1] + a[i];
  11.  
  12. while(q--){
  13. int x, y; cin>>x>>y;
  14. y = x-y;
  15. cout<<b[x]-b[y]<<endl;
  16. }
  17. }



54. Yet Another Tetris Problem

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. vector<int> a(n);
  8. for(int i=0; i<n; i++) cin>>a[i];
  9. bool possible=true;
  10. for(int i=0; i<n; i++)
  11. if(a[i]%2!=a[0]%2)
  12. possible=false;
  13. cout<<(possible?"YES":"NO")<<endl;
  14. }
  15. }



53. Vasilije in Cacak

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int main(){
  6. int t; cin>>t;
  7. while(t--){
  8. ll n, k, x;
  9. cin>>n>>k>>x;
  10. ll total = n*(n+1)/2;
  11. ll min_sum = k*(k+1)/2;
  12. ll max_sum = total - (n-k)*(n-k+1)/2;
  13. if(x>= min_sum and x<=max_sum)
  14. cout<<"YES"<<endl;
  15. else cout<<"NO"<<endl;
  16. }
  17. }



52. Decoding

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; cin >> n;
  6. string s; cin >> s;
  7.  
  8. if (n & 1) {
  9. for (int i = n - 1; i >= 0; i--) {
  10. if (i % 2 == 1) cout << s[i];
  11. }
  12. for (int i = 0; i < n; i++) {
  13. if (i % 2 == 0) cout << s[i];
  14. }
  15. } else {
  16. for (int i = n - 1; i >= 0; i--) {
  17. if (i % 2 == 0) cout << s[i];
  18. }
  19. for (int i = 0; i < n; i++) {
  20. if (i % 2 == 1) cout << s[i];
  21. }
  22. }
  23.  
  24. return 0;
  25. }



51. Oath of the Night's Watch

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int a[n], mx=INT_MIN, mn=INT_MAX;
  6. for(int i=0; i<n; i++){
  7. cin>>a[i];
  8. mx = max(mx,a[i]);
  9. mn = min(mn, a[i]);
  10. }
  11. int cnt_max=0, cnt_min=0;
  12.  
  13. for(int i=0; i<n; i++) {
  14. if(a[i]==mx) cnt_max++;
  15. if(a[i]==mn) cnt_min++;
  16. }
  17.  
  18. if(mx==mn) cout<<0;
  19. else cout<<(n - cnt_max - cnt_min);
  20. return 0;
  21. }



50. Exciting Bets

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll a,b;
  8. cin>>a>>b;
  9. if(a==b) cout<<0<<" "<<0<<'\n';
  10. else{
  11. ll x = abs(a-b);
  12. ll y = a%x;
  13. y = min(y, x-y);
  14. cout<<x<<" "<<y<<'\n';
  15. }
  16. }
  17. }



49. Orac and Factors

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. long long int n,k;
  7. cin>>n>>k;
  8. if(n%2==0) cout<<n+2*k<<endl;
  9. else {
  10. int d;
  11. for(int i=n; i>2; i--)
  12. if(n%i==0) d = i;
  13. cout<<n+d+ 2*(k-1)<<endl;
  14. }
  15. }
  16. }



48. The Corridor or There and Back Again

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. int k=INT_MAX, room, timer;
  8. vector<pair<int, int>> v;
  9. for(int i=0; i<n; i++){
  10. cin>>room>>timer;
  11. v.push_back({room, timer});
  12. }
  13.  
  14. for(int i=0; i<v.size(); i++)
  15. k = min(k, v[i].first + (v[i].second-1)/2);
  16. cout<<k<<endl;
  17. }
  18. }



47. Make Product Equal One

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin>>n;
  6. long long int z=0, neg=0, c=0;
  7. while(n--){
  8. long long int a; cin>>a;
  9. if(a==0) z++;
  10. else if(a>0) c+= a-1;
  11. else c+= -a-1, neg++;
  12. }
  13. if(z) c += z;
  14. else if(neg%2==1) c+=2;
  15. cout<<c<<endl;
  16. }


46. Odd Queries

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long n, q, t, a[200005], pref[200005];
  4. int main(){
  5. cin>>t;
  6. while(t--){
  7. cin>>n>>q;
  8. for(int i=1;i<=n; i++){
  9. cin>>a[i];
  10. pref[i] = pref[i-1]+a[i];
  11. }
  12. for(int i=0;i<q; i++){
  13. long long l,r,k; cin>>l>>r>>k;
  14. long long sum = pref[l-1] + (r-l+1)*k + pref[n]-pref[r];
  15. if(sum%2==1) cout<<"YES"<<endl;
  16. else cout<<"NO"<<endl;
  17. }
  18. }
  19. }



45. Dominant Piranha

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n, mx=0; cin>>n;
  7. vector<int> a(n);
  8. for(auto &p:a) {cin>>p; mx=max(mx,p);}
  9.  
  10. int idx=-1;
  11. for(int i=0; i<n; i++){
  12. if(a[i]!=mx) continue;
  13. if(i>0 && a[i-1]!=mx || i<n-1 && a[i+1]!=mx) idx=i+1;
  14. }
  15. cout<<idx<<endl;
  16. }
  17. return 0;
  18. }



44. Lunch Rush

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, k;
  5. cin>>n>>k;
  6. int f, t, m = INT_MIN;
  7. while(n--){
  8. cin>>f>>t;
  9. m = max(m, (t>k)?(f+k-t):f);
  10. }
  11. cout<<m;
  12. }



43. DIV + MOD

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int l,r,x;
  7. cin>>l>>r>>x;
  8. int ans = r/x + r%x;
  9. int m = r/x*x - 1;
  10. if(m>=l) ans = max(ans, m/x + m%x);
  11. cout<<ans<<endl;
  12. }
  13. }


42. Almost Prime

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[3001];
  4. int main(){
  5. int n, cnt=0; cin>>n;
  6. for(int i=2; i<=n; i++){
  7. if(a[i]==0) {
  8. for(int j=i; j<=n; j+=i) a[j]++;
  9. }
  10. if(a[i]==2) cnt++;
  11. }
  12. cout<<cnt<<endl;
  13. }




41. Distance and Axis

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int a,k; cin>>a>>k;
  8. if(a<k) cout<<k-a<<endl;
  9. else cout<<(a+k)%2<<endl;
  10. }
  11. }




40. PizzaForces

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. long long n; cin>>n;
  7. cout<<max(6LL,n+1)/2*5<<endl;
  8. }
  9. }



39. Bad Boy

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n, m, i, j;
  7. cin>>n>>m>>i>>j;
  8. cout<<1<<" "<<1<<" "<<n<<" "<<m<<"\n";
  9. }
  10. }



38. Mocha and Math

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n; cin>>n;
  7. int a[n];
  8. for(int i=0; i<n; i++) cin>>a[i];
  9. int j = a[0];
  10. for(int i=1; i<n; i++)
  11. j &= a[i];
  12. cout<<j<<endl;
  13. }
  14. }



37. Lights Out

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int a[5][5];
  5. memset(a,0,sizeof(a));
  6. for(int i=1; i<=3; i++)
  7. for(int j=1; j<=3; j++)
  8. cin>>a[i][j];
  9. for(int i=1; i<=3; i++, cout<<endl)
  10. for(int j=1; j<=3; j++)
  11. cout<<(( a[i][j]
  12. + a[i-1][j]
  13. + a[i+1][j]
  14. + a[i][j-1]
  15. + a[i][j+1] ) %2==0);
  16. }



36. Everyone Loves to Sleep

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n,h, m; cin>>n>>h>>m;
  8. int t1 = 60*h+m; //cout<<t1<<endl;
  9. int ans = 24*60;
  10. for(int i=0; i<n; i++){
  11. cin>>h>>m;
  12. int t2=60*h+m-t1;
  13. if(t2<0) t2+=24*60;
  14. ans = min(ans, t2);
  15. }
  16. cout<<ans/60<<" "<<ans%60<<endl;
  17. }
  18. }




35. Nastya and Rice

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n, a, b, c, d;
  8. cin>>n>>a>>b>>c>>d;
  9. int l=n*(a-b), r=n*(a+b);
  10. if(r<c-d || c+d<l) cout<<"No\n";
  11. else cout<<"Yes\n";
  12. }
  13. }



34. Juicer

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, b, d, a, sum=0, cnt=0;
  6. cin>>n>>b>>d;
  7. for(int i=0; i<n; i++){
  8. cin>>a;
  9. if(a<=b) sum+=a;
  10. if(sum>d) sum=0, cnt++;
  11. }
  12. cout<<cnt;
  13. }



33. Balanced Round

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5. int n, k; cin>>n>>k;
  6. vector<int> a(n);
  7. for(auto &i:a ) cin>>i;
  8. sort(a.begin(), a.end());
  9.  
  10. int cnt=1, ans=1;
  11. for(int i=1; i<n; i++){
  12. if(a[i]-a[i-1]>k) cnt=1;
  13. else cnt++;
  14. ans = max(cnt, ans);
  15. }
  16. cout<<n-ans<<endl;
  17. }
  18.  
  19. int main(){
  20. int t; cin>>t;
  21. while(t--) solve();
  22. }



32. Food Buying

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. cout<<n+(n-1)/9<<endl;
  9. }
  10. }



31. Array Reodering

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n, ans=0; cin>>n;
  8. vector<int> a(n);
  9. for(int &x: a) cin>>x;
  10.  
  11. //sorting based on even/odd
  12. sort(a.begin(), a.end(), [](int x, int y){return x%2 < y%2;});
  13.  
  14. //cnt no. of good index pairs
  15. for(int i=0; i<n; i++){
  16. for(int j=i+1; j<n; j++){
  17. ans += __gcd(a[i],a[j]*2)>1;
  18. }
  19. }
  20. cout<<ans<<endl;
  21. }
  22. }



30. Stripes

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. bool red=false;
  8. for(int i=1; i<=8; i++){
  9. string s; cin>>s;
  10. if(s=="RRRRRRRR") red=true;
  11. }
  12. if(red) cout<<"R"<<endl;
  13. else cout<<"B"<<endl;
  14. }
  15. }



29. Lineland Mail

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin>>n;
  6. int a[n];
  7.  
  8. for(int i=0; i<n; i++) cin>>a[i];
  9.  
  10. cout<<abs(a[0]-a[1])<<" "<<abs(a[0]-a[n-1])<<endl;
  11.  
  12. for(int i=1; i<n-1; i++)
  13. cout<<min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))<<" "<<max(abs(a[i]-a[0]),abs(a[i]-a[n-1]))<<endl;
  14.  
  15. cout<<abs(a[n-1]-a[n-2])<<" "<<abs(a[n-1]-a[0])<<endl;
  16.  
  17. return 0;
  18.  
  19. }



28. Unique Number

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n;
  8. string s;
  9. for(int i=9; i>0; i--) {
  10. if(n>=i) s=to_string(i)+s, n-=i;
  11. }
  12. cout << (n==0 ? s : "-1") << "\n";
  13. }
  14. }



27. Filling Diamonds

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n; cin>>n; cout<<n<<endl;
  8. }
  9. }


26. 01 Game

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. string s; cin>>s;
  7. int a[2] = {};
  8. for(char c : s) a[c-'0']++;
  9. cout<<(min(a[0],a[1])%2?"DA":"NET")<<endl;
  10. }
  11. }


25. Party

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, a[2000], temp, ans=0, cnt;
  5. cin>>n;
  6. for(int i=1; i<=n; i++){
  7. cin>>a[i];
  8. }
  9. for(int i=1; i<=n; i++){
  10. temp = a[i], cnt=1;
  11. while(temp!=-1) cnt++, temp = a[temp];
  12. ans = max(ans, cnt);
  13. }
  14. cout<<ans;
  15. }


24. Magic Numbers

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. string s; cin>>s;
  6. for(int i=0; i<s.length();){
  7.  
  8. if(s[i]!='1' && s[i]!='4') {cout<<"NO"; return 0;}
  9. else if(s[i]=='1' && s[i+1]=='4' && s[i+2]=='4') i+=3;
  10. else if(s[i]=='1' && s[i+1]=='4') i+=2;
  11.  
  12. else if(s[i]=='1') i++;
  13.  
  14. else { cout<<"NO"; return 0;}
  15. }
  16. cout<<"YES";
  17. }



23. Kana and Dragon Quest game

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int x,n,m; cin>>x>>n>>m;
  8. while(n--){
  9. int temp = (x/2)+10;
  10. if(x<=temp) break;
  11. x = temp;
  12. }
  13. if(x<=m*10) cout<<"YES"<<endl;
  14. else cout<<"NO"<<endl;
  15. }
  16. }



22. Make AP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int a, b, c; cin>>a>>b>>c;
  8.  
  9. //ye actual hai
  10. int A = b - (c-b);
  11. int B = a + (c-a)/2;
  12. int C = b + (b-a);
  13. //a mein dikkat
  14. if(A!=0 && A>=a && A%a==0) cout<<"YES\n";
  15. //b mein dikkat
  16. else if(B && B>=b && B%b==0 && (c-a)%2==0) cout<<"YES\n";
  17.  
  18. //c mein dikkat
  19. else if(C && C>=c && C%c==0) cout<<"YES\n";
  20.  
  21. //kuch nhi ho skta
  22. else cout<<"NO\n";
  23. }
  24. }



21. Two-gram

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, mc=0; //max count mc
  6. string s, ss, twogram; //substring ss
  7. map<string, int> smp; //string map smp
  8. cin>>n>>s;
  9. for(int i=0; i<n-1; i++){
  10. ss = s[i], ss+=s[i+1], smp[ss]++; //AB:1
  11. if(smp[ss]>mc) mc=smp[ss], twogram=ss;
  12. }
  13. cout<<twogram;
  14. }



20. Business trip

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int k, cnt=0, a[12]; //12 months
  5. cin>>k;
  6. for(int i=0; i<12; i++) cin>>a[i];
  7. sort(a, a+12);
  8. for(int i=11; i>=0; i--){
  9. if(k<=0) { cout<<cnt; return 0;}
  10. k-=a[i];
  11. cnt++;
  12. }
  13. cout<<(k<=0?cnt:-1); return 0;
  14. }



19. Case of the Zeros and Ones

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, cnt=0;
  6. char c; cin>>n;
  7. while(n--){
  8. cin>>c;
  9. if(c=='1') cnt++;
  10. else cnt--;
  11. }
  12. cout<<abs(cnt);
  13. }



18. Construct the String

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. string s;
  7. int n, a, b;
  8. cin>>n>>a>>b;
  9. for(int i=0; i<b; i++) s+='a'+i;
  10. for(int i=0; i<a-b; i++) s+=s[i];
  11. for(int i=0; i<n-a; i++) s+=s[i];
  12. cout<<s<<endl;
  13. }
  14. }


17. Keyboard

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. char c,i; cin>>c;
  6. string s = "qwertyuiopasdfghjkl;zxcvbnm,./";
  7. while(cin>>i){
  8. cout<<s[s.find(i)-(c=='R')+(c=='L')];
  9. }
  10. return 0;
  11. }


16. Vasya and Socks

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, m, days=0;
  6. cin>>n>>m;
  7. for(int i=1; i<=n; i++){
  8. if(i%m == 0) n++;
  9. days++;
  10. }
  11. cout<<days;
  12. }


15. Multiply by 2, divide by 6

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main(){
  5. ll n, cnt, t;
  6. cin>>t;
  7. while(t--){
  8. cin>>n;
  9. cnt = 0;
  10. while(n%6==0) n/=6, cnt+=1;
  11. while(n%3==0) n/=3, cnt+=2;
  12. if(n!=1) cnt=-1;
  13. cout<<cnt<<endl;
  14. }
  15. }



14. New Year's Number

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5. long long int n,x,y; cin>>n;
  6. for(x=0; x<=1000; x++){
  7. y = n - (2020*x);
  8. if(y<0) break;
  9. else if(y%2021==0)
  10. {
  11. cout<<"YES"<<endl;
  12. return;
  13. }
  14. else continue;
  15. }
  16. cout<<"NO"<<endl;
  17. }
  18.  
  19. int main(){
  20. int t; cin>>t;
  21. while(t--){
  22. solve();
  23. }
  24. }



13. Candies

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. int n, x; cin>>n;
  8. for(int k=2; k<=30; k++)
  9. {
  10. int dr = pow(2,k)-1;
  11. if(n%dr) continue;
  12. x = n/dr;
  13. break;
  14. }
  15. cout<<x<<endl;
  16. }
  17. }




12. Sale

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, m; cin>>n>>m;
  5. int a[n], ans=0;
  6. for(int i=0; i<n; i++) cin>>a[i];
  7. sort(a,a+n);
  8. for(int i=0; i<m; i++){
  9. if(a[i]>=0) break;
  10. ans += a[i];
  11. }
  12. cout<<abs(ans);
  13. }



11. Odd Divisor

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main(){
  5. int t; cin>>t;
  6. while(t--){
  7. ll n; cin>>n;
  8. while(n%2==0) n/=2;
  9. cout<<(n>1 ? "YES" : "NO")<<endl;
  10. }
  11. }


10. Ilya and Bank Account

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. if(n<0){
  6. int no_ones = n/10;
  7. int no_tens = n/100 * 10 + n%10;
  8. cout<<max(no_ones, no_tens);
  9. } else {
  10. cout<<n;
  11. }
  12. }



9. Game With Sticks

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n,m;
  5. cin>>n>>m;
  6. if(min(n,m)%2) cout<<"Akshat";
  7. else cout<<"Malvika";
  8. }



8. Puzzles

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n,m; cin>>n>>m;
  5. int a[m];
  6. for(int i=0; i<m; i++) cin>>a[i];
  7. sort(a,a+m);
  8. int MIN = a[n-1]-a[0];
  9. for(int i=1; i+n-1<m; i++)
  10. MIN = min(MIN, a[i+n-1]-a[i]);
  11. cout<<MIN;
  12. }



7. Dubstep

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. string s; cin>>s;
  5. int flag = 0;
  6. for(int i=0; i<s.size(); i++){
  7. if(s[i]=='W' && s[i+1]=='U' && s[i+2]=='B') {
  8. if(flag==1) cout<<" ";
  9. i += 2;
  10. }
  11. else cout<<s[i], flag=1;
  12.  
  13. }
  14. }



6. Kefa and First Steps

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin>>n;
  6. int a[n], cnt=1, max=1;
  7. for(int i=0; i<n; i++){
  8. cin>>a[i];
  9. }
  10. for(int i=1; i<n; i++){
  11. if(a[i]>=a[i-1]) {
  12. cnt++;
  13. if(max<cnt) max=cnt;
  14. }
  15. else cnt=1;
  16. }
  17. cout<<max;
  18. }



5. Gravity Flip

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int c,r;
  6. vector<int> a;
  7. cin>>c;
  8.  
  9. for(int i=0; i<c; i++){
  10. cin>>r;
  11. a.push_back(r);
  12. }
  13.  
  14. sort(a.begin(), a.end());
  15.  
  16. for(int i=0; i<c; i++){
  17. cout<<a[i]<<" ";
  18. }
  19.  
  20. }



4. HQ9+

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. string s; cin>>s;
  5. for(int i=0; i<s.size(); i++){
  6. if(s[i]=='Q' || s[i]=='H' || s[i]=='9'){
  7. cout<<"YES";
  8. return 0;
  9. }
  10. }
  11. cout<<"NO";
  12. }



3. Even Odds

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. long long n,k;
  6. cin>>n>>k;
  7. n = (n+1)/2;
  8. if(k<=n) cout<<2*k-1;
  9. else cout<<(k-n)*2;
  10. }



2. Twins

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin>>n;
  6. int a[n], sum=0, cnt=0, curr=0;
  7.  
  8. for(int i=0; i<n; i++) cin>>a[i], sum+=a[i];
  9. sort(a,a+n);
  10. sum/= 2;
  11.  
  12. for(int i=n-1; i>=0; i--){
  13. curr+= a[i];
  14. cnt++;
  15. if(curr>sum) break;
  16. }
  17. cout<<cnt;
  18. }



1. Football

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. string a; cin>>a;
  6. int zero=0, one=0;
  7. for(int i=0; i<size(a); i++){
  8. cin>>a[i];
  9. if(a[i] == '0') {zero++; one=0;}
  10. else {one++; zero=0;}
  11. if(one==7 || zero==7) {break;}
  12. }
  13. if(one==7 || zero==7) {cout<<"YES";}
  14. else {cout<<"NO";}
  15. }