ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
     while(t--){
        ll n,l,r;
        cin>>n>>l>>r;
        vector<ll> v(n);
        for(ll &i:v) cin>>i;
        priority_queue<ll> pq2,empty;
        priority_queue<ll,vector<ll>,greater<ll>> pq1,pq3;
        ll sum{};
        sum=accumulate(v.begin()+l-1,v.begin()+r,0);
        for(ll i=0;i<l-1;i++) pq1.push(v[i]);
        for(ll i=r;i<n;i++) pq3.push(v[i]);
        for(ll i=l-1;i<r;i++) pq2.push(v[i]);
        ll curr_sum=sum;
        //case 1
        while(!pq1.empty() && !pq2.empty()){
            if(pq1.top()>=pq2.top()) break;
            else curr_sum-=(pq2.top()-pq1.top());
            pq1.pop();
            pq2.pop();
        }
        ll ans=curr_sum;
        curr_sum=sum;
        pq2.swap(empty);
        for(ll i=l-1;i<r;i++) pq2.push(v[i]);
        //case 2
        while(!pq3.empty() && !pq2.empty()){
            if(pq3.top()>=pq2.top()) break;
            else curr_sum-=(pq2.top()-pq3.top());
            pq3.pop();
            pq2.pop();
        }
        ans=min(ans,curr_sum);
        cout<<ans<<'\n';
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
     while(t--){
        ll n,l,r;
        cin>>n>>l>>r;
        vector<ll> v(n);
        for(ll &i:v) cin>>i;
        priority_queue<ll> pq2,empty;
        priority_queue<ll,vector<ll>,greater<ll>> pq1,pq3;
        ll sum{};
        sum=accumulate(v.begin()+l-1LL,v.begin()+r,0LL);
        for(ll i=0;i<l-1LL;i++) pq1.push(v[i]);
        for(ll i=r;i<n;i++) pq3.push(v[i]);
        for(ll i=l-1LL;i<r;i++) pq2.push(v[i]);
        ll curr_sum=sum;
        //case 1
        while(!pq1.empty() && !pq2.empty()){
            if(pq1.top()>=pq2.top()) break;
            else curr_sum-=(pq2.top()-pq1.top());
            pq1.pop();
            pq2.pop();
        }
        ll ans=curr_sum;
        curr_sum=sum;
        pq2.swap(empty);
        for(ll i=l-1LL;i<r;i++) pq2.push(v[i]);
        //case 2
        while(!pq3.empty() && !pq2.empty()){
            if(pq3.top()>=pq2.top()) break;
            else curr_sum-=(pq2.top()-pq3.top());
            pq3.pop();
            pq2.pop();
        }
        ans=min(ans,curr_sum);
        cout<<ans<<'\n';
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void dfs(int curr,vector<int> adj[],vector<bool> &vis){
    vis[curr]=true;
    for(int &child:adj[curr]){
        if(vis[child]==false) dfs(child,adj,vis);
    }
}
int num_cc(vector<int> adj[],int n,int v1,int v2){
    int ans{};
    vector<bool> vis(n,false);
    for(int i=0;i<n;i++){
        if(vis[i]==false && i!=v1 && i!=v2){
            ans++;
            dfs(i,adj,vis);
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
     while(t--){
        int n;
        cin>>n;
        vector<int> adj[n];
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
        }
        if(n==2){
            cout<<0<<'\n';
            continue;
        }
        int v1,v2{-1},m1{},m2{};
        for(int i=0;i<n;i++){
            if(adj[i].size()>m1){
                m1=adj[i].size();
                v1=i;
            }
        }
        for(int i=0;i<n;i++){
            if(i==v1){
                adj[i].clear();
                continue;
            }
            adj[i].erase(remove(adj[i].begin(),adj[i].end(),v1),adj[i].end());
        }
        for(int i=0;i<n;i++){
            if(adj[i].size()>m2){
                m2=adj[i].size();
                v2=i;
            }
        }
        if(v2==-1){
            for(int i=0;i<n;i++){
                if(i!=v1){
                    v2=i;
                    break;
                }
            }
        }
        else{
            for(int i=0;i<n;i++){
                if(i==v2){
                    adj[i].clear();
                    continue;
                }
                adj[i].erase(remove(adj[i].begin(),adj[i].end(),v2),adj[i].end());
            }
        }
        int ans=num_cc(adj,n,v1,v2);
        cout<<ans<<'\n';
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
     while(t--){
        int n;
        cin>>n;
        vector<int> adj[n];
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
        }
        unordered_map <int,int> m;
        for(int i=0;i<n;i++){
            m[i]=adj[i].size();
        }
        int ans{};
        set <pair<int,int>> adj_pairs;
        for(int i=0;i<n;i++){
            for(int &j:adj[i]){
                ans=max(ans,m[i]+m[j]-2);
                adj_pairs.insert({i,j});
            }
        }
        vector<pair<int,int>> temp(n);
        for(int i=0;i<n;i++) temp.emplace_back(m[i],i);
        sort(temp.begin(),temp.end(),[](pair<int,int> p1,pair<int,int> p2){return p1.first>p2.first;});
        for(int i=0;i<n-1;i++){
            if(!adj_pairs.count({temp[i].second,temp[i+1].second})){
                ans=max(ans,temp[i].first+temp[i+1].first-1);
            }
        }
        cout<<ans<<'\n';
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
     while(t--){
        int n;
        cin>>n;
        vector<int> adj[n];
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
        }
        int ans{};
        unordered_map <int,int> deg;
        multiset <int> s;
        for(int i=0;i<n;i++) deg[i]=adj[i].size();
        for(int i=0;i<n;i++) s.insert(adj[i].size());
        for(int curr=0;curr<n;curr++){
            auto iter=s.find(deg[curr]);
            s.erase(iter);
            for(int &adj_node:adj[curr]){
                auto it=s.find(deg[adj_node]);
                s.erase(it);
                s.insert(deg[adj_node]-1);
            }
            int temp=*(s.rbegin());
            ans=max(ans,temp+deg[curr]-1);
            for(int &adj_node:adj[curr]){
                auto it=s.find(deg[adj_node]-1);
                s.erase(it);
                s.insert(deg[adj_node]);
            }
            s.insert(deg[curr]);
        }
        cout<<ans<<'\n';
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
     while(t--){
        int n;
        cin>>n;
        vector<int> adj[n];
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
        }
        unordered_map <int,int> m;
        for(int i=0;i<n;i++){
            m[i]=adj[i].size();
        }
        int ans{};
        set <pair<int,int>> adj_pairs;
        for(int i=0;i<n;i++){
            for(int &j:adj[i]){
                ans=max(ans,m[i]+m[j]-2);
                adj_pairs.insert({i,j});
            }
        }
        vector<pair<int,int>> temp(n);
        for(int i=0;i<n;i++) temp.emplace_back(m[i],i);
        sort(temp.begin(),temp.end(),[](pair<int,int> p1,pair<int,int> p2){return p1.first>p2.first;});
        for(int i=0;i<n-1;i++){
            if(!adj_pairs.count({temp[i].second,temp[i+1].second})){
                ans=max(ans,temp[i].first+temp[i+1].first-1);
                break;
            }
        }
        cout<<ans<<'\n';
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
     while(t--){
        int n;
        cin>>n;
        vector<int> adj[n];
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
        }
        unordered_map <int,int> m;
        for(int i=0;i<n;i++){
            m[i]=adj[i].size();
        }
        int ans{};
        set <pair<int,int>> adj_pairs;
        for(int i=0;i<n;i++){
            for(int &j:adj[i]){
                ans=max(ans,m[i]+m[j]-2);
                adj_pairs.insert({i,j});
            }
        }
        vector<pair<int,int>> temp(n);
        for(int i=0;i<n;i++) temp.emplace_back(m[i],i);
        sort(temp.begin(),temp.end(),[](pair<int,int> p1,pair<int,int> p2){return p1.first>p2.first;});
        for(int i=0;i<n-1;i++){
            if(!adj_pairs.count({temp[i].second,temp[i+1].second})){
                ans=max(ans,temp[i].first+temp[i+1].first-1);
            }
        }
        cout<<ans<<'\n';
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int t;
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    
    scanf("%d",&t);
    while(t--){
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-'0'-1+'0';
						s[i+1]=p;
						break;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

int t;
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    
    scanf("%d",&t);
    while(t--){
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-1;
						s[i+1]=p;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int t,a[200008];
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    memset(a,-1,sizeof(a));
    scanf("%d",&t);
    while(t--){
    	memset(a,-1,sizeof(a));
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-'0'-1+'0';
						s[i+1]=p;
						break;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int t,a[200008];
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    memset(a,-1,sizeof(a));
    scanf("%d",&t);
    while(t--){
    	memset(a,-1,sizeof(a));
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-'0'-1+'0';
						s[i+1]=p;
						break;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int t;
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    
    scanf("%d",&t);
    while(t--){
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-'0'-1+'0';
						s[i+1]=p;
						break;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        ll l, r;
        cin>>l>>r;

        ll num = l^r;
        ll size = log2(num)+1;
        num = 0;
        ll a = 1;
        while(size--) {
            num += a;
            a *= 2;
        }
        ll b = num^r;
        cout<<b<<" "<<r<<" "<<r<<endl;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        ll l, r;
        cin>>l>>r;

        ll num = l^r;
        ll size = log2(num)+1;
        num = 0;
        ll a = 1;
        while(size--) {
            num += a;
            a *= 2;
        }
        ll b = num^r;
        cout<<b<<" "<<r<<" "<<r<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        ll l, r;
        cin>>l>>r;
        ll ans = 0;
        for(int i = 30; i >= 0; i--) {
            ll b1 = l & (1ll << i);
            ll b2 = r & (1ll << i);
            if(b1 == b2) {
                ans += b1;
            } else {
                ans += 1ll << i;
            }
        }
        ll ans2 = ans-1;
        ll ans3;
        for(int i = l; i <= r; i++) {
            if(i != ans && i != ans2) {
                ans3 = i;
                break;
            }
        }
        cout<<ans<<" "<<ans2<<" "<<ans3<<endl;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        ll l, r;
        cin>>l>>r;
        ll ans = 0;
        for(int i = 30; i >= 0; i--) {
            ll b1 = l & (1ll << i);
            ll b2 = r & (1ll << i);
            if(b1 == b2) {
                ans += b1;
            } else {
                ans += 1ll << i;
            }
        }
        ll ans2 = ans-1;
        ll ans3;
        for(int i = l; i <= r; i++) {
            if(i != ans && i != ans2) {
                ans3 = i;
                break;
            }
        }
        cout<<ans<<" "<<ans2<<" "<<ans3<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        ll l, r;
        cin>>l>>r;
        ll ans = 0;
        for(int i = 30; i >= 0; i--) {
            ll b1 = l & (1ll << i);
            ll b2 = r & (1ll << i);
            if(b1 == b2) {
                ans += b1;
            } else {
                ans += 1ll << i;
                break;
            }
        }
        ll ans2 = ans-1;
        ll ans3;
        for(int i = l; i <= r; i++) {
            if(i != ans && i != ans2) {
                ans3 = i;
                break;
            }
        }
        cout<<ans<<" "<<ans2<<" "<<ans3<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            if(i%2) k = abs(k);
            ans = max(ans, k);
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n-1; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            
            ans = max(ans, abs(k));
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n-1; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            
            ans = max(ans, abs(k));
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n-1; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            if(i != 0) k = abs(k);
            ans = max(ans, k);
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n-1; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            if(i%2) k = abs(k);
            ans = max(ans, k);
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            if(i%2) k = abs(k);
            ans = max(ans, k);
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin>>a[i];
        }
        if(n==1){
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < n-1; i++) {
            ll k = 0;
            for(int j = 0; j < n-i; j++) {
                k += a[j];
               
            }
            if(i%2) k = abs(k);
            ans = max(ans, k);
            for(int j = 0; j < n-i-1; j++) {
                a[j] = a[j+1]-a[j];
            }       
        }
        
        ans = max(ans, abs(a[0]));
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: Python 3

Previous submission (verdict: Wrong answer on test 2):
n=int(input())
for i in range(n):
    a,b = list(map(int, input().split()))
    arr = list(map(int, input().strip().split()))
    d = dict.fromkeys(arr, 0)
    for i in arr:
        d[i] += 1
    new_arr = sorted(list(d.values()), reverse=True)
    m = new_arr[0]
    for i in new_arr:
        i=i-m
    if b == 0:
        i = 0
    else:
        for i in range(1,len(new_arr)):
            if new_arr[i] <= b:
                b=b-new_arr[i]
                if b == 0:
                    break
            else:
                b=b-new_arr[i]
                break
    print(len(new_arr) - i)
            

Submission (verdict: Time limit exceeded on test 12):
n=int(input())
for i in range(n):
    a,b = list(map(int, input().split()))
    arr = list(map(int, input().strip().split()))
    d = dict.fromkeys(arr, 0)
    for i in arr:
        d[i] += 1
    new_arr = sorted(list(d.values()))
    for i in range(len(new_arr)):
        if b == 0:
            break
        if b >= new_arr[i]:
            b = b - new_arr[i]
        else:
            break
    print(len(new_arr) - i)