ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
 int t;
 cin >> t;

 for (int _ = 0; _ < t; _++) {
  int n, k;
  cin >> n >> k;

  unordered_map<int, int> as;
  for (int i = 0; i < n; i++) {
   int tmp;
   cin >> tmp;
   as[tmp]++;
  }

  int* a{new int[n]};
  int index = 0;
  for (const auto &pair : as) {
   a[index++] = pair.second;
  }

  sort(a, a + index);
  int counter = 0;
  for (int i = 0; i < index; i++) {
   if (a[i] <= k)
    k -= a[i];
   else
    counter++;
  }
  if (counter > 1)
   cout << counter << endl;
  else
   cout << 1 << endl;
 }
}


Submission (verdict: Compilation error):
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
 int t;
 cin >> t;

 for (int _ = 0; _ < t; _++) {
  int n, k;
  cin >> n >> k;

  map<int, int> as;
  for (int i = 0; i < n; i++) {
   int tmp;
   cin >> tmp;
   as[tmp]++;
  }

  int* a{new int[n]};
  int index = 0;
  for (const auto &pair : as) {
   a[index++] = pair.second;
  }

  sort(a, a + index);
  int counter = 0;
  for (int i = 0; i < index; i++) {
   if (a[i] <= k)
    k -= a[i];
   else
    counter++;
  }
  if (counter > 1)
   cout << counter << endl;
  else
   cout << 1 << endl;
 }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
 int t;
 cin >> t;

 for (int _ = 0; _ < t; _++) {
  int n, k;
  cin >> n >> k;

  map<int, int> as;
  for (int i = 0; i < n; i++) {
   int tmp;
   cin >> tmp;
   as[tmp]++;
  }

  int* a{new int[n]};
  int index = 0;
  for (const auto &pair : as) {
   a[index++] = pair.second;
  }

  sort(a, a + index);
  int counter = 0;
  for (int i = 0; i < index; i++) {
   if (a[i] <= k)
    k -= a[i];
   else
    counter++;
  }
  if (counter > 1)
   cout << counter << endl;
  else
   cout << 1 << endl;
 }
}


Submission (verdict: Accepted):
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
 int t;
 cin >> t;

 for (int _ = 0; _ < t; _++) {
  int n, k;
  cin >> n >> k;

  map<int, int> as;
  for (int i = 0; i < n; i++) {
   int tmp;
   cin >> tmp;
   as[tmp]++;
  }

  int* a{new int[n]};
  int index = 0;
  for (const auto &pair : as) {
   a[index++] = pair.second;
  }

  sort(a, a + index);
  int counter = 0;
  for (int i = 0; i < index; i++) {
   if (a[i] <= k)
    k -= a[i];
   else
    counter++;
  }
  if (counter > 1)
   cout << counter << endl;
  else
   cout << 1 << endl;
 }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 11):
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
 int t;
 cin >> t;

 for (int _ = 0; _ < t; _++) {
  int n, k;
  cin >> n >> k;

  unordered_map<int, int> as;
  for (int i = 0; i < n; i++) {
   int tmp;
   cin >> tmp;
   as[tmp]++;
  }

  int* a{new int[n]};
  int index = 0;
  for (const auto &pair : as) {
   a[index++] = pair.second;
  }

  sort(a, a + index);
  int counter = 0;
  for (int i = 0; i < index; i++) {
   if (a[i] <= k)
    k -= a[i];
   else
    counter++;
  }
  if (counter > 1)
   cout << counter << endl;
  else
   cout << 1 << endl;
 }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

#define ll          long long

#define vi          vector<int>
#define vl          vector<long long>
#define vll          vector<vector<long long>>
#define vii         vector<vector<int>>

#define pb          push_back
#define pf          push_front
#define fr          front
#define eb          emplace_back
#define ff          first
#define ss          second
#define endl        "\n"

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 

#define MOD         1e9 + 7

// ------------------------------- //

void solve(){
    ll n;cin>>n;
    vl arr(n);
    for(ll &x : arr) cin>>x;

    vll steps;
    
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            steps.push_back({arr[j],arr[j+1]});
            swap(arr[j],arr[j+1]);
        }
    }

    for(int i=n-1;i>0;i--){
        int j = i;
        while(arr[j-1] != j && j>0){
            steps.push_back({arr[j-1],arr[j]});
            swap(arr[i],arr[j]);
            j--;
        }

    }
    // cout<<steps<<endl;

    cout<<steps.size()<<endl;
    for(int i=steps.size()-1;i>=0;i--){
        for(auto x : steps[i]) cout<<x<<' ';
        cout<<endl;
    }


}

int main()
{
    FAST_IO;
    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define fi for(int i=0;i<n;i++)
#define fit(a) for(auto it:a)
#define pb push_back
#define pf push_front
#define mi map<int,int>
#define umi unordered_map<int,int>
#define usi unordered_set<int>
#define maxheapint priority_queue<int>
#define maxheappair priority_queue<pair<int,int>>
#define minheapint priority_queue<int,vector<int>,greater<int>>
#define minheappair priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
using namespace std;
void print(vector<int> &a){
    for(auto i:a) cout<<i<<" ";
    cout<<"\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vi a(n);
        fi cin>>a[i];
        vi b(a.begin()+l-1,a.begin()+r);
        int ans=accumulate(b.begin(),b.end(),0);
        sort(b.begin(),b.end(),greater<int>());
        vi left,right;
        int ans1=ans,ans2=ans;
        for(int i=0;i<l-1;i++){
            left.push_back(a[i]);
        }
        for(int i=r;i<n;i++){
            right.push_back(a[i]);
        }
        sort(left.begin(),left.end());
        sort(right.begin(),right.end());
        vi left1,right1;
        int szl=left.size(),szr=right.size();
        for(int i=0;i<min(szl,r-l+1);i++) left1.push_back(left[i]);
        for(int i=0;i<min(szr,r-l+1);i++) right1.push_back(right[i]);
        int z=0,s=0;
        while(z<left1.size() && s<b.size() && left1[z]<b[s]){
            ans1+=left1[z++];
            ans1-=b[s++];
        }
        z=0,s=0;
        while(z<right1.size() && s<b.size() && right1[z]<b[s]){
            ans2+=right1[z++];
            ans2-=b[s++];
        }
        // cout<<"ARRAY: ";
        // print(a);
        // cout<<"ARRAY B: ";
        // print(b);
        // cout<<"LEFT : ";
        // print(left);
        // cout<<"RIGHT: ";
        // print(right);
        // cout<<"ans1 and 2: ";
        // cout<<ans1<<" "<<ans2<<"\n";
        // cout<<"FINAL\n";
        cout<<min(ans1,ans2)<<"\n";
        cout<<"END\n";
    }   
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 8):
#include<iostream>
using namespace std;

int arr[200001];
int temp[200001];
void merge ( int *arr, int l1, int r1, int l2, int r2 ) {
	int i = l1, j = l1;
	while ( l1 <= r1 && l2 <= r2 ) {
		temp[i++] = arr[l1] < arr[l2] ? arr[l1++] : arr[l2++];
	}
	while ( l1 <= r1 || l2 <= r2 ) {
		temp[i++] = l1 <= r1 ? arr[l1++] : arr[l2++];
	}
	while ( j <= r2 ) {
		arr[j++] = temp[j];
	}
}
void divide ( int *arr, int l, int r ) {
	if ( l == r ) return;
	divide ( arr, l, ( l + r ) / 2 );
	divide ( arr, ( l + r ) / 2 + 1, r );
	merge ( arr, l, ( l + r ) / 2, ( l + r ) / 2 + 1, r );
}
void solve();

signed main() {

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

return 0;

}

void solve() {
	int n, l, r, i, sum = 0, mn, rem_sum = 0, add_sum = 0, p1, p2;
	cin >> n >> l >> r;
	for ( i = 0; i < n; i++ ) {
		cin >> arr[i];
		if ( i >= l - 1 && i <= r - 1 ) {
			sum += arr[i]; 
		}
	}
	mn = sum;
	if ( l > 1 ) {
		divide ( arr, 0, l - 2 );
	}
	divide ( arr, l - 1, r - 1 );
	if ( r < n ) {
		divide ( arr, r, n - 1 );
	}
	p1 = r - 1;
	p2 = 0;
	while ( p1 >= l - 1 && p2 < l - 1 ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = sum - rem_sum + add_sum; 
	rem_sum = add_sum = 0;
	p1 = r - 1;
	p2 = r; 
	while ( p1 >= l - 1 && p2 < n ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = mn > sum - rem_sum + add_sum ? sum - rem_sum + add_sum : mn;
	cout << mn << "\n";
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include<iostream>
using namespace std;

int arr[200001];
int temp[200001];
void merge ( int *arr, int l1, int r1, int l2, int r2 ) {
	int i = l1, j = l1;
	while ( l1 <= r1 && l2 <= r2 ) {
		temp[i++] = arr[l1] < arr[l2] ? arr[l1++] : arr[l2++];
	}
	while ( l1 <= r1 || l2 <= r2 ) {
		temp[i++] = l1 <= r1 ? arr[l1++] : arr[l2++];
	}
	while ( j <= r2 ) {
		arr[j++] = temp[j];
	}
}
void divide ( int *arr, int l, int r ) {
	if ( l == r ) return;
	divide ( arr, l, ( l + r ) / 2 );
	divide ( arr, ( l + r ) / 2 + 1, r );
	merge ( arr, l, ( l + r ) / 2, ( l + r ) / 2 + 1, r );
}
void solve();

signed main() {

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

return 0;

}

void solve() {
	int n, l, r, i, sum = 0, mn, rem_sum = 0, add_sum = 0, p1, p2;
	cin >> n >> l >> r;
	for ( i = 0; i < n; i++ ) {
		cin >> arr[i];
		if ( i >= l - 1 && i <= r - 1 ) {
			sum += arr[i]; 
		}
	}
	mn = sum;
	if ( l > 1 ) {
		divide ( arr, 0, l - 2 );
	}
	divide ( arr, l - 1, r - 1 );
	if ( r < n ) {
		divide ( arr, r, n - 1 );
	}
	p1 = r - 1;
	p2 = 0;
	while ( p1 >= l - 1 && p2 < l - 1 ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = sum - rem_sum + add_sum; 
	rem_sum = add_sum = 0;
	p1 = r - 1;
	p2 = r; 
	while ( p1 >= l - 1 && p2 < n ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = mn > sum - rem_sum + add_sum ? sum - rem_sum + add_sum : mn;
	cout << mn << "\n";
}



Submission (verdict: Wrong answer on test 8):
#include<iostream>
using namespace std;

int arr[200001];
int temp[200001];
void merge ( int *arr, int l1, int r1, int l2, int r2 ) {
	int i = l1, j = l1;
	while ( l1 <= r1 && l2 <= r2 ) {
		temp[i++] = arr[l1] < arr[l2] ? arr[l1++] : arr[l2++];
	}
	while ( l1 <= r1 || l2 <= r2 ) {
		temp[i++] = l1 <= r1 ? arr[l1++] : arr[l2++];
	}
	while ( j <= r2 ) {
		arr[j++] = temp[j];
	}
}
void divide ( int *arr, int l, int r ) {
	if ( l == r ) return;
	divide ( arr, l, ( l + r ) / 2 );
	divide ( arr, ( l + r ) / 2 + 1, r );
	merge ( arr, l, ( l + r ) / 2, ( l + r ) / 2 + 1, r );
}
void solve();

signed main() {

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

return 0;

}

void solve() {
	int n, l, r, i, p1, p2;
	long sum = 0, mn, rem_sum = 0, add_sum = 0; 
	cin >> n >> l >> r;
	for ( i = 0; i < n; i++ ) {
		cin >> arr[i];
		if ( i >= l - 1 && i <= r - 1 ) {
			sum += arr[i]; 
		}
	}
	mn = sum;
	if ( l > 1 ) {
		divide ( arr, 0, l - 2 );
	}
	divide ( arr, l - 1, r - 1 );
	if ( r < n ) {
		divide ( arr, r, n - 1 );
	}
	p1 = r - 1;
	p2 = 0;
	while ( p1 >= l - 1 && p2 < l - 1 ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = sum - rem_sum + add_sum; 
	rem_sum = add_sum = 0;
	p1 = r - 1;
	p2 = r; 
	while ( p1 >= l - 1 && p2 < n ) {
		if ( arr[p1] > arr[p2] ) {
			rem_sum += arr[p1--];
			add_sum += arr[p2++];
		}
		else {
			break;
		}
	}
	mn = mn > sum - rem_sum + add_sum ? sum - rem_sum + add_sum : mn;
	cout << mn << "\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;
#define ll long long int

int main() {
	ll t;
	cin >> t;
	
	for(ll j=1;j<=t;j++) {
		ll z;
		cin >> z;
		vector<set<ll>> tree(z + 1);
		vector<ll> v;
		for (ll i = 0; i < z - 1; i++) {
			ll x, y;
			cin >> x >> y;
			v.push_back(x);
			v.push_back(y);
			tree[x].insert(y);
			tree[y].insert(x);
		}
		if(j==1142)
		{
			for(ll i=0;i<v.size();i++)
			{
				cout<<v[i]<<" ";
			}
			cout<<endl;
		}
	  bool isall2=0;
	  ll count1=0,count2=0;
	  for(ll i=1;i<=z;i++)
	  {
	  	if(tree[i].size()==1)
		{
			count1++;
		}
		else if(tree[i].size()==2)
		{
			count2++;
		}
	  }

	  if(z>=5&&count2==z-2&&count1==2)
	  {
	  	isall2=1;
	  }
		ll connected = 0, idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ll ans = 1;
		ans += tree[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree[idx]) {
			tree[x].erase(idx);
		}
		tree[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ans += tree[idx].size()-1;
		if(isall2)
		{
			cout<<"3"<<endl;
		}
		else{
		cout << ans << endl;
		}
	}
	
	return 0;
}
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;
#define ll long long int

int main() {
	ll t;
	cin >> t;
	
	for(ll j=1;j<=t;j++) {
		ll z;
		cin >> z;
		vector<set<ll>> tree(z + 1);
		vector<ll> v;
		for (ll i = 0; i < z - 1; i++) {
			ll x, y;
			cin >> x >> y;
			v.push_back(x);
			v.push_back(y);
			tree[x].insert(y);
			tree[y].insert(x);
		}
		if(j==1142)
		{
			for(ll i=0;i<v.size();i++)
			{
				cout<<v[i];
			}
			cout<<endl;
		}
	  bool isall2=0;
	  ll count1=0,count2=0;
	  for(ll i=1;i<=z;i++)
	  {
	  	if(tree[i].size()==1)
		{
			count1++;
		}
		else if(tree[i].size()==2)
		{
			count2++;
		}
	  }

	  if(z>=5&&count2==z-2&&count1==2)
	  {
	  	isall2=1;
	  }
		ll connected = 0, idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ll ans = 1;
		ans += tree[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree[idx]) {
			tree[x].erase(idx);
		}
		tree[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ans += tree[idx].size()-1;
		if(isall2)
		{
			cout<<"3"<<endl;
		}
		else{
		cout << ans << endl;
		}
	}
	
	return 0;
}




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

int main() {
	ll t;
	cin >> t;
	
	while (t--) {
		ll z;
		cin >> z;
		vector<set<ll>> tree(z + 1);
		
		for (ll i = 0; i < z - 1; i++) {
			ll x, y;
			cin >> x >> y;
			tree[x].insert(y);
			tree[y].insert(x);
		}
		vector<set<ll>> tree1=tree;
		ll connected = 0, idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ll ans = 1;
		ans += tree[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree[idx]) {
			tree[x].erase(idx);
		}
		tree[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ans += tree[idx].size()-1;
		
		
		 connected = 0;
		  idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree1[i].size()) {
				connected = tree1[i].size();
				idx = i;
			}
		}

		ll ans1 = 1;
		ans1 += tree1[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree1[idx]) {
			tree1[x].erase(idx);
		}
		tree1[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree1[i].size()) {
				connected = tree1[i].size();
				idx = i;
			}
		}

		ans1 += tree[idx].size()-1;
		cout <<max(ans,ans1)<< endl;
	}
	
	return 0;
}
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;
#define ll long long int

int main() {
	ll t;
	cin >> t;
	
	for(ll j=1;j<=t;j++) {
		ll z;
		cin >> z;
		vector<set<ll>> tree(z + 1);
		vector<ll> v;
		for (ll i = 0; i < z - 1; i++) {
			ll x, y;
			cin >> x >> y;
			v.push_back(x);
			v.push_back(y);
			tree[x].insert(y);
			tree[y].insert(x);
		}
		if(j==1142)
		{
			for(ll i=0;i<v.size();i++)
			{
				cout<<v[i]<<" ";
			}
			cout<<endl;
		}
	  bool isall2=0;
	  ll count1=0,count2=0;
	  for(ll i=1;i<=z;i++)
	  {
	  	if(tree[i].size()==1)
		{
			count1++;
		}
		else if(tree[i].size()==2)
		{
			count2++;
		}
	  }

	  if(z>=5&&count2==z-2&&count1==2)
	  {
	  	isall2=1;
	  }
		ll connected = 0, idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ll ans = 1;
		ans += tree[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree[idx]) {
			tree[x].erase(idx);
		}
		tree[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ans += tree[idx].size()-1;
		if(isall2)
		{
			cout<<"3"<<endl;
		}
		else{
		cout << ans << endl;
		}
	}
	
	return 0;
}




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

int main() {
	ll t;
	cin >> t;
	
	for(ll j=1;j<=t;j++) {
		ll z;
		cin >> z;
		vector<set<ll>> tree(z + 1);
		vector<ll> v;
		for (ll i = 0; i < z - 1; i++) {
			ll x, y;
			cin >> x >> y;
			v.push_back(x);
			v.push_back(y);
			tree[x].insert(y);
			tree[y].insert(x);
		}
		if(j==1142)
		{
			for(ll i=0;i<v.size();i++)
			{
				cout<<v[i];
			}
			cout<<endl;
		}
	  bool isall2=0;
	  ll count1=0,count2=0;
	  for(ll i=1;i<=z;i++)
	  {
	  	if(tree[i].size()==1)
		{
			count1++;
		}
		else if(tree[i].size()==2)
		{
			count2++;
		}
	  }

	  if(z>=5&&count2==z-2&&count1==2)
	  {
	  	isall2=1;
	  }
		ll connected = 0, idx = 1;
		
		// Finding the most connected node
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ll ans = 1;
		ans += tree[idx].size()-1;
		// Remove first selected node's edges
		for (auto x : tree[idx]) {
			tree[x].erase(idx);
		}
		tree[idx].clear();

		// Find the next most connected node
		connected = 0, idx = 1;
		for (ll i = 1; i <= z; i++) {
			if (connected < (ll)tree[i].size()) {
				connected = tree[i].size();
				idx = i;
			}
		}

		ans += tree[idx].size()-1;
		if(isall2)
		{
			cout<<"3"<<endl;
		}
		else{
		cout << ans << endl;
		}
	}
	
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

int main() {
	int t;
	cin>>t;
	while(t--){
	    long long int n,l,r;
	    cin>>n>>l>>r;
	    vector<long long int>vec(n);
	    for(int i=0;i<n;i++){
	        cin>>vec[i];
	    }
	    sort(vec.begin(), vec.end());
	    long long int  ans=r-l;
	    long long int ans1=0;
	    for(int i=0;i<=ans;i++){
	        ans1+=vec[i];
	    }
	    cout<<ans1<<endl;
	}

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

int main() {
	int t;
	cin>>t;
	while(t--){
	    long long int n,l,r;
	    cin>>n>>l>>r;
	    vector<long long int>vec(n);
	    for(int i=0;i<n;i++){
	        cin>>vec[i];
	    }
	    sort(vec.begin(), vec.end());
	    long long int  ans=r-l;
	    long long int ans1=0;
	    for(int i=0;i<=ans;i++){
	        ans1+=vec[i];
	    }
	    cout<<ans1<<endl;
	}

}


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

int main() {
    int t;
    cin >> t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>vec(n);
        vector<int>vec2(r);
        vector<int>vec3(n-l+1);
        int j=0;
        int k=0;
        for(int i=0;i<n;i++){
            cin>>vec[i];
            if(i<r){
                vec2[j]=vec[i];
                j++;
            }
            if(i>=(l-1)){
                vec3[k]=vec[i];
                k++;
            }
        }
        sort(vec2.begin(),vec2.end());
        sort(vec3.begin(),vec3.end());
        int m=r-l+1;
        int sum1=0;
        int sum2=0;
        for(int i=0;i<m;i++){
            if(i<vec2.size()){
                sum1+=vec2[i];
            }
            if(i<vec3.size()){
                sum2+=vec3[i];
            }

        }
        if(vec2.size()==0){
            cout<<sum2<<endl;
        }
        else if(vec3.size()==0){
            cout<<sum1<<endl;
        }
        else{
            cout<<min(sum1,sum2)<<endl;
        }

    }
}