ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
//                                               <-------GAUTAM KUMAR SHAH------->          
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long mod=1e9+7;
#define loop(i,n)      for(int i=0;i<n;i++)
#define loopr(i,n)      for(int i=n;i>0;i--)
#define cin(arr,n)     for(int i=0;i<n;i++) cin>>arr[i];
#define loopv(i,k,n)   for(int i=k;i<n;i++)
#define vi vector<long long int>
#define mi map<long long int,long long int>
ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod
ll mminv(ll a) {return mod_expo(a, mod-2);}
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;}  //only for prime m
ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i<n+1 ; i++)
fac[i]=(fac[i-1]*i)%mod;return(fac[n]*mminv(fac[r])%mod*mminv(fac[n-r])%mod)%mod;} 
 
int solve(string &a,string &b,string &c,int i,int j){
    int a1=a.size();
    int b1=b.size();
    int c1=c.size();
    int k=i+j;
    if(k==a1+b1){
        return 0;
    }
    int pick1=INT_MAX,npick1=INT_MAX,pick2=INT_MAX,npick2=INT_MAX;
    if(a[i]==c[k]){
        pick1=(solve(a,b,c,i+1,j));
    }
    if(b[j]==c[k]){
        pick2=(solve(a,b,c,i,j+1));
    }
    npick1=(1+solve(a,b,c,i+1,j));
    npick2=(1+solve(a,b,c,i,j+1));
    return min(min(pick1,pick2),min(npick1,npick2));


}
 
int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
   int t;
   cin>>t;
   while(t--)
   {
        string a,b,c;
        cin>>a>>b>>c;
        int ans=solve(a,b,c,0,0);
        cout<<ans<<endl;
 
   }
   return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
//Author : Choudhary Reyan Khan 
 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Auto auto
#define Endl '\n'
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int N = 1e5 + 10;

vector<int> adj[200001];
int to_from[200001];
int dp[200001];

void help(){
   int n, l, r;
   cin>>n>>l>>r;
   vector<int> arr(n);
   for(auto&i:arr)cin>>i;
   int k = min(n,abs(l-r));
   sort(all(arr));
   int ans = 0ll;
   int i = 0;
   while(k--) ans+=arr[i++];
   if(i < n)ans+=arr[i];
   cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int T = 1;
   cin>>T;
  while(T--){
    help();
  }
  return 0;
}

Submission (verdict: Wrong answer on test 2):
//Author : Choudhary Reyan Khan 
 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Auto auto
#define Endl '\n'
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int N = 1e5 + 10;

vector<int> adj[200001];
int to_from[200001];
int dp[200001];

void help(){
   int n, l, r;
   cin>>n>>l>>r;
   vector<int> arr(n);
   for(auto&i:arr)cin>>i;
   int k = min(n,abs(l-r));
   sort(all(arr));
   int ans1 = 0ll;
   int i = 0;
   while(k--) ans1+=arr[i++];
   if(i < n)ans1+=arr[i];
   int ans2 = 0;
   reverse(all(arr));
   k = min(n,abs(l-r));
   i=0;
   while(k--) ans2+=arr[i++];
   if(i < n) ans2+=arr[i];  
   cout << (int)(min(ans1,ans2)) << endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int T = 1;
   cin>>T;
  while(T--){
    help();
  }
  return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
//Author : Choudhary Reyan Khan 
 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Auto auto
#define Endl '\n'
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int N = 1e5 + 10;

vector<int> adj[200001];
int to_from[200001];
int dp[200001];

void help(){
   int n, l, r;
   cin>>n>>l>>r;
   vector<int> arr(n);
   for(auto&i:arr)cin>>i;
   int k = min(n,abs(l-r));
   sort(all(arr));
   int ans = 0ll;
   int i = 0;
   while(k--) ans+=arr[i++];
   if(i < n)ans+=arr[i];
   cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int T = 1;
   cin>>T;
  while(T--){
    help();
  }
  return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
//Author : Choudhary Reyan Khan 
 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Auto auto
#define Endl '\n'
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int N = 1e5 + 10;

vector<int> adj[200001];
int to_from[200001];
int dp[200001];

void help(){
   int n, l, r;
   cin>>n>>l>>r;
   vector<int> arr(n);
   for(auto&i:arr)cin>>i;
   int k = min(n,abs(l-r));
   sort(all(arr));
   int ans1 = 0ll;
   int i = 0;
   while(k--) ans1+=arr[i++];
   if(i < n)ans1+=arr[i];
   int ans2 = 0;
   reverse(all(arr));
   k = min(n,abs(l-r));
   i=0;
   while(k--) ans2+=arr[i++];
   if(i < n) ans2+=arr[i];  
   cout << (int)(min(ans1,ans2)) << endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int T = 1;
   cin>>T;
  while(T--){
    help();
  }
  return 0;
}

Submission (verdict: Accepted):
//Author : Choudhary Reyan Khan 



#include<bits/stdc++.h>

using namespace std;

#define int long long int

#define Auto auto

#define Endl '\n'

#define all(x) x.begin(),x.end()



const int mod = 1e9+7;

const int N = 1e5 + 10;



vector<int> adj[200001];

int to_from[200001];

int dp[200001];



void help(){

   int n, l, r;

   cin>>n>>l>>r;

   l--;

   vector<int> arr(n);

   for(auto&i:arr)cin>>i;

   vector<int> brr=arr, crr=arr;

   sort(brr.begin()+l,brr.end());

   sort(crr.begin(),crr.begin()+r,greater<int>());

   int ans1 = 0;

   int ans2 = 0;

   int i = l;

   int k = min(r-l,(int)brr.size()-l);

   while(k--) ans1+=brr[i++];

   i = l;

   k = min(r-l,(int)crr.size()-l);

   while(k--)ans2+=crr[i++];

   cout << min(ans1,ans2) << Endl;

}



signed main(){

  ios::sync_with_stdio(false);

  cin.tie(0);

  cout.tie(0);

  int T = 1;

   cin>>T;

  while(T--){

    help();

  }

  return 0;

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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        l--,r--;
        long long arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        vector<long long> a,b;

        for(int i=l;i<n; i++){
            b.push_back(arr[i]);
        }
        for(int i=0;i<=r; i++){
            a.push_back(arr[i]);
        }
        sort(a.begin(),a.end());
        sort(b.end(),b.end());
        long long s1=accumulate(a.begin(), a.begin()+ (int)(r-l+1), 0LL);
        long long s2=accumulate(b.begin(), b.begin()+ (int)(r-l+1), 0LL);
        cout<<min(s1,s2)<<"\n";
        
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        l--,r--;
        long long arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        vector<long long> a,b;

        for(int i=l;i<n; i++){
            b.push_back(arr[i]);
        }
        for(int i=0;i<=r; i++){
            a.push_back(arr[i]);
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        long long s1=accumulate(a.begin(), a.begin()+ (int)(r-l+1), 0LL);
        long long s2=accumulate(b.begin(), b.begin()+ (int)(r-l+1), 0LL);
        cout<<min(s1,s2)<<"\n";
        
    }
}
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;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        int arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        sort(arr,arr+r);
        long long s1=0;
        long long s2=0;
        for(int i=0; i<(r-l+1); i++){
            s1+=arr[i];
        }
        sort(arr+l-1,arr+n);
        for(int i=l-1; i<(r); i++){
            s2+=arr[i];
        }
        cout<<min(s1,s2)<<"\n";
        
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        long long arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        sort(arr,arr+r);
        long long s1=0;
        long long s2=0;
        for(int i=0; i<(r-l+1); i++){
            s1+=arr[i];
        }
        sort(arr+l-1,arr+n);
        for(int i=l-1; i<(r); i++){
            s2+=arr[i];
        }
        cout<<min(s1,s2)<<"\n";
        
    }
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        int arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        sort(arr,arr+r);
        long long s1=0;
        long long s2=0;
        for(int i=0; i<(r-l+1); i++){
            s1+=arr[i];
        }
        sort(arr+l-1,arr+n);
        for(int i=l-1; i<(r); i++){
            s2+=arr[i];
        }
        cout<<min(s1,s2)<<"\n";
        
    }
}
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;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        long long arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        sort(arr,arr+r);
        long long s1=0;
        long long s2=0;
        for(int i=0; i<(r-l+1); i++){
            s1+=arr[i];
        }
        sort(arr+l-1,arr+n);
        for(int i=l-1; i<(r); i++){
            s2+=arr[i];
        }
        cout<<min(s1,s2)<<"\n";
        
    }
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,l,r,n;
    cin>>t;
    while(t--){
        cin>>n>>l>>r;
        l--,r--;
        long long arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        vector<long long> a,b;

        for(int i=l;i<n; i++){
            b.push_back(arr[i]);
        }
        for(int i=0;i<=r; i++){
            a.push_back(arr[i]);
        }
        sort(a.begin(),a.end());
        sort(b.end(),b.end());
        long long s1=accumulate(a.begin(), a.begin()+ (int)(r-l+1), 0LL);
        long long s2=accumulate(b.begin(), b.begin()+ (int)(r-l+1), 0LL);
        cout<<min(s1,s2)<<"\n";
        
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <utility>
#include <array>
#include <vector>
#include <deque>
#include <forward_list>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <functional>
#include <popcntintrin.h>
#include <ext/pb_ds/assoc_container.hpp>

// LLONG_MAX is 9,223,372,036,854,775,807 (19 digits)
// ULLONG_MAX is 18,446,744,073,709,551,615 (20 digits)

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<std::pair<T, T>, null_type, std::less<std::pair<T, T>>, rb_tree_tag, tree_order_statistics_node_update>;

// use a map to keep track of duplicates in ordered multiset, like 2-1, 2-2, 2-3, and so on

using ll = long long;
using ld = long double;
using namespace std;

void solve()
{
    ll n;
    cin >> n;
    
    vector<ll> c(n);
    set<ll> st;
    
    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
        st.insert(i + 1);
    }
    
    vector<pair<ll, ll>> events;
    
    while (!c.empty())
    {
        ll a = c.back();
        c.pop_back();
        
        for (auto &x : st)
        {
            if (x == a)
            {
                break;
            }
            
            events.emplace_back(a, x);
        }
        
        st.erase(a);
        
        for (auto &x : st)
        {
            events.emplace_back(x, a);
        }
    }
    
    cout << (ll) events.size() << '\n';
    
    for (auto &[x, y] : events)
    {
        cout << x << " " << y << '\n';
    }
}

// Increase Stack Size for Meta HackerCup

// static void run_with_stack_size(void (*func)(void), size_t stsize)
// {
//     char *stack, *send;
//     stack = (char *)malloc(stsize);
//     send = stack + stsize - 16;
//     send = (char *)((uintptr_t)send / 16 * 16);
//     asm volatile(
//         "mov %%rsp, (%0)\n"
//         "mov %0, %%rsp\n"
//         :
//         : "r"(send));
//     func();
//     asm volatile("mov (%0), %%rsp\n"
//                  :
//                  : "r"(send));
//     free(stack);
// }

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	// USACO
	// freopen("whereami.in", "r", stdin);
	// freopen("whereami.out", "w", stdout);

	// Codeforces, AtCoder

	ll ncases = 1;
// 	cin >> ncases;

	while (ncases--)
	{
		solve();
	}

	// Meta HackerCup

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	// int ncases = 1;
	// cin >> ncases;

	// for (int i = 1; i <= ncases; i++)
	// {
	//     std::cout << "Case #" << i << ": ";
	//     run_with_stack_size(solve, 1024 * 1024 * 1024); // run with a 1 GiB stack
	// }

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

const int N = 3e5 + 9;
using ll = long long;

#define int long long int

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            if(i+2<n)
            {
                if(a[i+1]>a[i+2])
                {
                    cout<<"NO"<<'\n';
                    return;
                }
            }
        }
    }
    if(n == 2)
    {
        if(a[1]>a[0])
        {
            cout<<"NO"<<'\n';
            return;
        }
    }
    cout<<"YES"<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    return 0;
}


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

const int N = 3e5 + 9;
using ll = long long;

#define int long long int

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int j = 0;
    for(int i=1;i<n;i++)
    {
        if(a[i-1]>a[i]) j=i;
    }
    if(j==0)
    {
        cout<<"YES"<<'\n';
        return;
    }

    auto fop = [&](int i){
        int minN = min(a[i],a[i+1]);
        a[i] -= minN;
        a[i+1] -= minN;
    };

    for(int i=0;i<j-1;i++)
    {
        fop(i);
    }
    cout<<(is_sorted(a.begin(),a.end())?"YES":"NO")<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

const int N = 3e5 + 9;
using ll = long long;

#define int long long int

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            if(i+2<n)
            {
                if(a[i+1]>a[i+2])
                {
                    cout<<"NO"<<'\n';
                    return;
                }
            }
        }
    }
    cout<<"YES"<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    return 0;
}


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

const int N = 3e5 + 9;
using ll = long long;

#define int long long int

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            if(i+2<n)
            {
                if(a[i+1]>a[i+2])
                {
                    cout<<"NO"<<'\n';
                    return;
                }
            }
        }
    }
    if(n == 2)
    {
        if(a[1]>a[0])
        {
            cout<<"NO"<<'\n';
            return;
        }
    }
    cout<<"YES"<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

const int N = 3e5 + 9;
using ll = long long;

#define int long long int

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
        {
            if(i+2<n)
            {
                if(a[i+1]>a[i+2])
                {
                    cout<<"NO"<<'\n';
                    return;
                }
            }
        }
    }
    cout<<"YES"<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    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 int long long 

signed main()
{
    int tt;
    cin>>tt;

    while(tt--)
    {
        int n;
        cin>>n;

        unordered_map<int, vector<int>> adj;
        vector<int> deg(n);

        for(int i=0; i<n-1; i++)
        {
            int u, v;
            cin>>u>>v;

            u--; v--;
            
            adj[u].push_back(v);
            adj[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        set<pair<int, int>> st;
        int ans = 0;

        for(int i=0; i<n; i++)
        {
            st.erase({deg[i], i});

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]--;
                st.insert({deg[v], v});
            }

            int temp = deg[i]-1;
            temp+=(*st.rbegin()).first;
            ans = max(ans, temp);

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]++;
                st.insert({deg[v], v});
            }
        }

        cout<<ans<<endl;
    }

    return 0;
}

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

#define int long long 

signed main()
{
    int tt;
    cin>>tt;

    while(tt--)
    {
        int n;
        cin>>n;

        unordered_map<int, vector<int>> adj;
        vector<int> deg(n);

        for(int i=0; i<n-1; i++)
        {
            int u, v;
            cin>>u>>v;

            u--; v--;
            
            adj[u].push_back(v);
            adj[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        set<pair<int, int>> st;
        int ans = 0;

        for(int i=0; i<n; i++)
        {
            st.erase({deg[i], i});

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]--;
                st.insert({deg[v], v});
            }

            int temp = adj[i].size()-1;
            temp+=(*st.rbegin()).first;
            ans = max(ans, temp);

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]++;
                st.insert({deg[v], v});
            }
            
            st.insert({deg[i], i});
        }

        cout<<ans<<endl;
    }

    return 0;
}
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 int long long 

void dfs(unordered_map<int, vector<int>>& adj, int index, int p, vector<int>& parent, vector<int>& c_count)
{
    int count = 0;

    for(int i : adj[index])
    {
        if(i != p)
        {
            parent[i] = index;
            count++;
            dfs(adj, i, index, parent, c_count);
        }
    }

    c_count[index] = count;
}

signed main()
{
    int tt;
    cin >> tt;

    while(tt--)
    {
        int n;
        cin >> n;

        unordered_map<int, vector<int>> adj;

        for(int i = 0; i < n - 1; i++)
        {
            int u, v;
            cin >> u >> v;

            u--;
            v--;

            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        vector<int> parent(n, -1);
        vector<int> c_count(n, 0);

        dfs(adj, 0, -1, parent, c_count);
        set<pair<int, int>> st;

        for(int i = 0; i < n; i++) st.insert({c_count[i], i});

        int ans = 0;

        int f = (*st.rbegin()).second;
        st.erase(*st.rbegin());

        ans += c_count[f];
        auto record = st.find({c_count[parent[f]], parent[f]});
        if(record != st.end()) st.erase(record);

        if(f!=0)st.insert({c_count[parent[f]] - 1, parent[f]});

        if(!st.empty())
        {
            ans += (*st.rbegin()).first;
            st.erase(prev(st.end()));
        }

        if(st.empty())
        {
            cout << 0 << endl;
            continue;
        }

        cout << ans << endl;
    }

    return 0;
}