ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;

void solve(){
    int n,u,v;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0;i<n-1;++i){
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    auto comp = [](pair<int,int> a, pair<int,int> b) { return a.fi > b.fi; };
    set<pair<int,int>, decltype(comp)> s(comp);
    for(int i = 0;i<n;++i){
        s.insert({sz(g[i]),i});
    }
    int ans = 0;
    for(int i = 0;i<n;++i){
        for(int j : g[i]){
            ans = max(ans, sz(g[j])+sz(g[i]) - 2);
            s.erase({sz(g[j]),j});
        }
        s.erase({sz(g[i]),i});
        auto u = s.begin();
        ans = max(ans,sz(g[i])+(*u).fi-1);
        for(int j : g[i]){
            s.insert({sz(g[j]),j});
        }
        s.insert({sz(g[i]),i});
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;

void solve(){
    int n,u,v;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0;i<n-1;++i){
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }

    set<pair<int,int>, greater<pair<int,int>>> s;
    for(int i = 0;i<n;++i){
        s.insert({sz(g[i]),i});
    }
    int ans = 0;
    for(int i = 0;i<n;++i){
        // cout << i << " : ";
        for(int j : g[i]){
            // cout << " ( " << j << " " << sz(g[j])+sz(g[i]) - 2 << " ) ";
            ans = max(ans, sz(g[j])+sz(g[i]) - 2);
            s.erase({sz(g[j]),j});
        }
        s.erase({sz(g[i]),i});
        auto u = s.begin();
        // cout << " ( " << (*u).se << " " << sz(g[i])+(*u).fi-1 << " ) " << '\n';
        ans = max(ans,sz(g[i])+(*u).fi-1);
        for(int j : g[i]){
            s.insert({sz(g[j]),j});
        }
        s.insert({sz(g[i]),i});
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const int N = 2e5+7;
const int inf = 1e9;
int dist[N];
bool comp(pair<int,int>& a,pair<int,int>& b){
    if(a.se == b.se) return dist[a.fi] < dist[b.fi];
    return a.se > b.se;
}

void bfs(vector<vector<int>>& g){
    int n = sz(g);
    for(int i = 0;i<n;++i){
        dist[i] = inf;
    }
    queue<int> q;
    for(int i = 0;i<n;++i){
        if(sz(g[i]) == 1){
            dist[i] = 0;
            q.push(i);
        }
    }
    while(!q.empty()){
        int v = q.front();
        q.pop();

        for(int i : g[v]){
            if(dist[i] > dist[v]+1){
                dist[i] = dist[v]+1;
                q.push(i);
            }
        }
    }
}

void solve(){
    int n,u,v;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0;i<n-1;++i){
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    bfs(g);
    vector<pair<int,int>> s;
    for(int i = 0;i<n;++i) s.pb({i,sz(g[i])});
    sort(all(s), comp);
    for(int i = 1;i<n;++i){
        bool k = false;
        for(int j : g[s[i].fi]){
            if(j == s[0].fi){
                k = true;
            }
        }
        if(k) s[i].se--;
    }
    sort(all(s), comp);
    cout << s[0].se + s[1].se - 1 << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) solve();
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;

void solve(){
    int n,u,v;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0;i<n-1;++i){
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    auto comp = [](pair<int,int> a, pair<int,int> b) { return a.fi > b.fi; };
    set<pair<int,int>, decltype(comp)> s(comp);
    for(int i = 0;i<n;++i){
        s.insert({sz(g[i]),i});
    }
    int ans = 0;
    for(int i = 0;i<n;++i){
        for(int j : g[i]){
            ans = max(ans, sz(g[j])+sz(g[i]) - 2);
            s.erase({sz(g[j]),j});
        }
        s.erase({sz(g[i]),i});
        auto u = s.begin();
        ans = max(ans,sz(g[i])+(*u).fi-1);
        for(int j : g[i]){
            s.insert({sz(g[j]),j});
        }
        s.insert({sz(g[i]),i});
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;

bool comp(pair<int,int>& a,pair<int,int>& b){
    return a.se > b.se;
}

void solve(){
    int n,u,v;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0;i<n-1;++i){
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    vector<pair<int,int>> s;
    for(int i = 0;i<n;++i) s.pb({i,sz(g[i])});
    sort(all(s), comp);
    for(int i = 1;i<n;++i){
        bool k = false;
        for(int j : g[s[i].fi]){
            if(j == s[0].fi){
                k = true;
            }
        }
        if(k) s[i].se--;
    }
    sort(all(s), comp);
    cout << s[0].se + s[1].se - 1 << '\n';
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        int idx;
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                idx = i.first;
            }
            // max = i.second;
        }
        m[idx] = 0;
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>0){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
    
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        if(n==1){
            cout<<1<<endl;
        }
        else{
            cout<<count+1<<endl;
        }
        // cout<<(count+1)<<endl;
   
}
}


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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int temp = k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        // int idx = v[0];
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                // idx = i.first;
            }
            // max = i.second;
        }
        // m[idx] = 0;
        // if (temp == 0){

        //     cout<<m.size()<<endl;
        //     continue;
        // }
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>=v2[i]){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
        // k = temp;
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        // if(n==1 || n==temp){
        //     cout<<1<<endl;
        // }
       
        // else{
        //     cout<<count<<endl;
        // }
        // cout<<m.size()<<endl;

        if(m.size() == temp && n == temp){
            cout<<1<<endl;
        }
        else{
            cout<<(count)<<endl;
        }
        
   
}
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int temp = k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        // int idx = v[0];
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                // idx = i.first;
            }
            // max = i.second;
        }
        // m[idx] = 0;
        // if (temp == 0){

        //     cout<<m.size()<<endl;
        //     continue;
        // }
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>=v2[i]){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
        // k = temp;
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        // if(n==1 || n==temp){
        //     cout<<1<<endl;
        // }
       
        // else{
        //     cout<<count<<endl;
        // }
        // cout<<m.size()<<endl;

        if(m.size() == temp && n == temp){
            cout<<1<<endl;
        }
        else{
            cout<<(count)<<endl;
        }
        
   
}
}


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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int temp = k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        // int idx = v[0];
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                // idx = i.first;
            }
            // max = i.second;
        }
        // m[idx] = 0;
        // if (temp == 0){

        //     cout<<m.size()<<endl;
        //     continue;
        // }
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>=v2[i]){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
        // k = temp;
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        
        // for(int i=0;i<v2.size();i++){
        //     cout<<v2[i]<<" ";
        // }cout<<endl;
        if(count == 0){
            cout<<1<<endl;
        }

        else if(m.size() == temp && n == temp ){
            cout<<1<<endl;
        }
        else{
            cout<<(count)<<endl;
        }
        
   
}
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        int idx;
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                idx = i.first;
            }
            // max = i.second;
        }
        m[idx] = 0;
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>0){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
    
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        if(n==1){
            cout<<1<<endl;
        }
        else{
            cout<<count+1<<endl;
        }
        // cout<<(count+1)<<endl;
   
}
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


Submission (verdict: Compilation error):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t;

    cin>>t;

    

    while(t--)

    {

        int n;

        cin>>n;

        

        int a[n];

        

        for(int i=0;i<n;i++)

        {

            cin>>a[i];

        }

        

        int sum=0;

        

        for(int i=0;i<n;;i++)

        {

            sum+=a[i];

        }

        

        if(sum%n==0)

        {

            cout<<"YES"<<"\n";

        }

        else

        {

            cout<<"NO"<<"\n";

        }

    }

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t;

    cin>>t;

    

    while(t--)

    {

        int n;

        cin>>n;

        

        int a[n];

        

        for(int i=0;i<n;i++)

        {

            cin>>a[i];

        }

        

        int sum=0;

        

        for(int i=0;i<n;;i++)

        {

            sum+=a[i];

        }

        

        if(sum%n==0)

        {

            cout<<"YES"<<"\n";

        }

        else

        {

            cout<<"NO"<<"\n";

        }

    }

}



Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t;

    cin>>t;

    

    while(t--)

    {

        int n;

        cin>>n;

        

        int a[n];

        

        for(int i=0;i<n;i++)

        {

            cin>>a[i];

        }

        

        int sum=0;

        

        for(int i=0;i<n;i++)

        {

            sum+=a[i];

        }

        

  

        

        if(sum%n==0)

        {

            int value = sum/n;

            int cnt1=0;

            int cnt2=0;

            

            for(int i=0;i<n;i++)

            {

                if(i%2==0)

                {

                   

                   cnt1+=a[i]-value; 

                }

                else

                {

                    cnt2+=a[i]-value;

                }

            }

            

            if(cnt1==0&&cnt2==0)

            {

            cout<<"YES"<<"\n";

            }

            else

            {

                cout<<"NO"<<"\n";

            }

        }

        else

        {

            cout<<"NO"<<"\n";

        }

    }

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t;

    cin>>t;

    

    while(t--)

    {

        int n;

        cin>>n;

        

        int a[n];

        

        for(int i=0;i<n;i++)

        {

            cin>>a[i];

        }

        

        int sum=0;

        

        for(int i=0;i<n;i++)

        {

            sum+=a[i];

        }

        

  

        

        if(sum%n==0)

        {

            int value = sum/n;

            int cnt1=0;

            int cnt2=0;

            

            for(int i=0;i<n;i++)

            {

                if(i%2==0)

                {

                   

                   cnt1+=a[i]-value; 

                }

                else

                {

                    cnt2+=a[i]-value;

                }

            }

            

            if(cnt1==0&&cnt2==0)

            {

            cout<<"YES"<<"\n";

            }

            else

            {

                cout<<"NO"<<"\n";

            }

        }

        else

        {

            cout<<"NO"<<"\n";

        }

    }

}



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

using namespace std;



int main() {

    int t;

    cin>>t;

    

    while(t--)

    {

        long long int n;

        cin>>n;

        

        long long int a[n];

        

        for(long long int i=0;i<n;i++)

        {

            cin>>a[i];

        }

        

        long long int sum=0;

        

        for(long long int i=0;i<n;i++)

        {

            sum+=a[i];

        }

        

  

        

        if(sum%n==0)

        {

            long long int value = sum/n;

            long long int cnt1=0;

            long long int cnt2=0;

            

            for(long long int i=0;i<n;i++)

            {

                if(i%2==0)

                {

                   

                   cnt1+=a[i]-value; 

                }

                else

                {

                    cnt2+=a[i]-value;

                }

            }

            

            if(cnt1==0&&cnt2==0)

            {

            cout<<"YES"<<"\n";

            }

            else

            {

                cout<<"NO"<<"\n";

            }

        }

        else

        {

            cout<<"NO"<<"\n";

        }

    }

}
Problem: 2063B - Subsequence Update
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.util.*;

import java.io.*;

public class MooCounting {

    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());



        while(t-- > 0)

        {

            StringTokenizer st = new StringTokenizer(br.readLine());

            int n = Integer.parseInt(st.nextToken());

            int left = Integer.parseInt(st.nextToken());

            int right = Integer.parseInt(st.nextToken());



            st = new StringTokenizer(br.readLine());

            int[] arr = new int[n];

            for(int i = 0; i < n; i++)

            {

                arr[i] = Integer.parseInt(st.nextToken());

            }



            int[] brr = arr.clone();

            int min = 0; 

            int k = right - left + 1;

            Arrays.sort(brr);

            for(int i = 0; i < k; i++)

            {

                min += brr[i];

            }

            System.out.println(min);    

        }

    }   

}

Submission (verdict: Wrong answer on test 8):
import java.util.*;

import java.io.*;

public class MooCounting {

    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());



        while(t-- > 0)

        {

            StringTokenizer st = new StringTokenizer(br.readLine());

            int n = Integer.parseInt(st.nextToken());

            int left = Integer.parseInt(st.nextToken());

            left--;

            int right = Integer.parseInt(st.nextToken());

            right--;



            st = new StringTokenizer(br.readLine());

            int[] arr = new int[n];

            for(int i = 0; i < n; i++)

            {

                arr[i] = Integer.parseInt(st.nextToken());

            }



            // Case 1

            int[] brr = arr.clone();

            Arrays.sort(brr, left, n); // Sort only [l, n]

            int sum1 = 0;

            for (int i = left; i <= right; i++) {

                sum1 += brr[i];

            }



            // Case 2

            int[] crr = arr.clone();

            Arrays.sort(crr, 0, right + 1); // Sort [0, r] normally

            reverse(crr, 0, right); 

            int sum2 = 0;

            for (int i = left; i <= right; i++) {

                sum2 += crr[i];

            }



            System.out.println(Math.min(sum1, sum2));  

        }

    }



    private static void reverse(int[] arr, int start, int end) {

        while (start < end) {

            int temp = arr[start];

            arr[start] = arr[end];

            arr[end] = temp;

            start++;

            end--;

        }

    }   

}
Problem: 2063B - Subsequence Update
Language: Java 21

Previous submission (verdict: Wrong answer on test 8):
import java.util.*;
import java.io.*;
public class MooCounting {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());

        while(t-- > 0)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int left = Integer.parseInt(st.nextToken());
            left--;
            int right = Integer.parseInt(st.nextToken());
            right--;
            int k = right - left + 1;

            st = new StringTokenizer(br.readLine());
            int[] arr = new int[n];
            for(int i = 0; i < n; i++)
            {
                arr[i] = Integer.parseInt(st.nextToken());
            }

            // Case 1: [l, n]
            int[] option1 = Arrays.copyOfRange(arr, left, n);
            Arrays.sort(option1);
            int sum1 = 0;
            for (int i = 0; i < k; i++) sum1 += option1[i];

            // Case 2: [1, r]
            int[] option2 = Arrays.copyOfRange(arr, 0, right + 1);
            Arrays.sort(option2);
            int sum2 = 0;
            for (int i = 0; i < k; i++) sum2 += option2[i];

            
            System.out.println(Math.min(sum1, sum2)); 
        }
    }
}

Submission (verdict: Accepted):
import java.util.*;

import java.io.*;

public class MooCounting {

    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());



        while(t-- > 0)

        {

            StringTokenizer st = new StringTokenizer(br.readLine());

            int n = Integer.parseInt(st.nextToken());

            int left = Integer.parseInt(st.nextToken());

            left--;

            int right = Integer.parseInt(st.nextToken());

            right--;

            long k = (long)right - (long)left + 1;



            st = new StringTokenizer(br.readLine());

            int[] arr = new int[n];

            for(int i = 0; i < n; i++)

            {

                arr[i] = Integer.parseInt(st.nextToken());

            }



            // Case 1: [l, n]

            int[] option1 = Arrays.copyOfRange(arr, left, n);

            Arrays.sort(option1);

            long sum1 = 0;

            for (int i = 0; i < k; i++) sum1 += option1[i];



            // Case 2: [1, r]

            int[] option2 = Arrays.copyOfRange(arr, 0, right + 1);

            Arrays.sort(option2);

            long sum2 = 0;

            for (int i = 0; i < k; i++) sum2 += option2[i];



            

            System.out.println(Math.min(sum1, sum2)); 

        }

    }

}