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

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <vector>

long long lcs(std::string& a, std::string& b)
{
    std::string substr;
    std::vector matrix(a.length() + 1, std::vector<long long>(b.length() + 1, 0));
    for(int i = 1; i < matrix.size(); ++i)
        for(int j = 1; j < matrix[0].size(); ++j)
        {
            if(a[i - 1] == b[j - 1])
                matrix[i][j] = matrix[i-1][j-1]+ 1;
            else
                matrix[i][j] = std::max(matrix[i-1][j], matrix[i][j-1]);
        }
    return matrix[a.length()][b.length()];
}



int main() {
    int t;
    std::cin >> t;
    while(t > 0)
    {
        std::string a, b, c;
        std::cin >> a;
        std::cin >> b;
        std::cin >> c;
        if(lcs(a, c) > 1 && lcs(b, c) > 1)
            std::cout << c.size() - lcs(a, c) - lcs(b, c);
        else if (lcs(a, c) <= 1 && lcs(b, c) > 1)
            std::cout << c.size() - lcs(b, c);
        else if (lcs(a, c) > 1 && lcs(b, c) <= 1)
            std::cout << c.size() - lcs(a, c);
        else if(lcs(a, c) <= 1 && lcs(b, c) <= 1)
            std::cout << c.size() - 1;
        --t;
    }
    
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>

long long lcs(std::string& a, std::string& b)
{
    std::string substr;
    std::vector matrix(a.length() + 1, std::vector<long long>(b.length() + 1, 0));
    for(int i = 1; i < matrix.size(); ++i)
        for(int j = 1; j < matrix[0].size(); ++j)
        {
            if(a[i - 1] == b[j - 1])
                matrix[i][j] = matrix[i-1][j-1]+ 1;
            else
                matrix[i][j] = std::max(matrix[i-1][j], matrix[i][j-1]);
        }
    return matrix[a.length()][b.length()];
}



int main() {
    int t;
    std::cin >> t;
    while(t > 0)
    {
        std::string a, b, c;
        std::cin >> a;
        std::cin >> b;
        std::cin >> c;
        if(lcs(a, c) > 1 && lcs(b, c) > 1)
            std::cout << c.size() - lcs(a, c) - lcs(b, c) << "\n";
        else if (lcs(a, c) <= 1 && lcs(b, c) > 1)
            std::cout << c.size() - lcs(b, c) << "\n";
        else if (lcs(a, c) > 1 && lcs(b, c) <= 1)
            std::cout << c.size() - lcs(a, c) << "\n";
        else if(lcs(a, c) <= 1 && lcs(b, c) <= 1)
            std::cout << c.size() - 1 << "\n";
        --t;
    }
    
    return 0;
}
Problem: 2063B - Subsequence Update
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,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r+1],main[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

       else if(i>=l-1&&i<=r-1){

        main[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main,main+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<=main[j]){

            swap(brr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<=main[j]){

            swap(crr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum=0;

       for(int k=0;k<index2;k++){

        sum+=main[k];

       }

       cout<<sum<<endl;

    }

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

      int n,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r+1],main1[r-l+1],main2[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

       else if(i>=l-1&&i<=r-1){

        main1[index2]=arr[i];

        main2[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main1,main1+index2);

      sort(main2,main2+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<=main1[j]){

            swap(brr[i],main1[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<=main2[j]){

            swap(crr[i],main2[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum1=0,sum2=0;

       for(int k=0;k<index2;k++){

        sum1+=main1[k];

       }

       for(int k=0;k<index2;k++){

        sum2+=main2[k];

       }

       cout<<min(sum1,sum2)<<endl;

    }

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

      int n,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r],main[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

       else if(i>=l-1&&i<=r-1){

        main[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main,main+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<main[j]){

            swap(brr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<main[j]){

            swap(crr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum=0;

       for(int k=0;k<index2;k++){

        sum+=main[k];

       }

       cout<<sum<<endl;

    }

}
Problem: 2063B - Subsequence Update
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,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r],main[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

       else if(i>=l-1&&i<=r-1){

        main[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main,main+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<main[j]){

            swap(brr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<main[j]){

            swap(crr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum=0;

       for(int k=0;k<index2;k++){

        sum+=main[k];

       }

       cout<<sum<<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,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r+1],main[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

       else if(i>=l-1&&i<=r-1){

        main[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main,main+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<=main[j]){

            swap(brr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<=main[j]){

            swap(crr[i],main[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum=0;

       for(int k=0;k<index2;k++){

        sum+=main[k];

       }

       cout<<sum<<endl;

    }

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

using ll= long long;

bool isSorted(vector<ll> v){

ll n=v.size();

for(ll i=0;i<n-1;i++){

if(v[i]>v[i+1]){

return false;

}

}

return true;

}

int main()

{

int t;

cin>>t;

while(t--){

ll n;

cin>>n;

vector<ll> v;

for(ll i=0;i<n;i++){

ll x;

cin>>x;

v.push_back(x);

}

for(ll i=0;i<n;i++){

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}else{

ll c=min(v[i],v[i+1]);

v[i]-=c;

v[i+1]-=c;

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}

}

}

if(!isSorted(v)){

cout<<"No"<<endl;

}

}



return 0;

}

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

using namespace std;

using ll= long long;

bool isSorted(vector<ll> v){

ll n=v.size();

if(is_sorted(v.begin(), v.end())){

return true;

}

return false;

}

int main()

{

int t;

cin>>t;

while(t--){

ll n;

cin>>n;

vector<ll> v;

for(ll i=0;i<n;i++){

ll x;

cin>>x;

v.push_back(x);

}

for(ll i=0;i<n;i++){

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}else{

ll c=min(v[i],v[i+1]);

v[i]-=c;

v[i+1]-=c;

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}

}

}

if(!isSorted(v)){

cout<<"No"<<endl;

}

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

using ll= long long;

bool isSorted(vector<ll> v){

ll n=v.size();

for(ll i=0;i<n-1;i++){

if(v[i]>v[i+1]){

return false;

}

}

return true;

}

int main()

{

int t;

cin>>t;

while(t--){

ll n;

cin>>n;

vector<ll> v;

for(ll i=0;i<n;i++){

ll x;

cin>>x;

v.push_back(x);

}

for(ll i=0;i<n;i++){

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}else{

ll c=min(v[i],v[i+1]);

v[i]-=c;

v[i+1]-=c;

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}

}

}

if(!isSorted(v)){

cout<<"No"<<endl;

}

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

using ll= long long;

bool isSorted(vector<ll> v){

ll n=v.size();

if(is_sorted(v.begin(), v.end())){

return true;

}

return false;

}

int main()

{

int t;

cin>>t;

while(t--){

ll n;

cin>>n;

vector<ll> v;

for(ll i=0;i<n;i++){

ll x;

cin>>x;

v.push_back(x);

}

for(ll i=0;i<n;i++){

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}else{

ll c=min(v[i],v[i+1]);

v[i]-=c;

v[i+1]-=c;

if(isSorted(v)){

cout<<"Yes"<<endl;

break;

}

}

}

if(!isSorted(v)){

cout<<"No"<<endl;

}

}



return 0;

}

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

using namespace std;

using ll= long long;

int main()

{

int t;

cin>>t;

while(t--){

ll n;

cin>>n;

vector<ll> v;

for(ll i=0;i<n;i++){

ll x;

cin>>x;

v.push_back(x);

}

for(ll i=0;i<n-1;i++){

if(v[i]>v[i+1]){

cout<<"No"<<endl;

break;

}else{

ll temp = v[i];

v[i]-=temp;

v[i+1]-=temp;

}

}

if(is_sorted(v.begin(),v.end())){

cout<<"Yes"<<endl;

}

}



return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;
// using namespace __gnu_pbds;

#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define MOD 1000000007
#define PI 3.141592653589793238462

typedef long long ll;

const int inf = 0x3f3f3f3f;
const int maxn = 2e6 + 6;
const double eps = 1e-8;
const int mod = 998244353;
const int N = 1e5 + 7;

// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ll powerFun(ll x, ll p) { ll res = 1; for (int i = 1; i <= p; i++) { res *= x; } return res; }
// ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
// bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
// vector<ll> prime; void sieve_of_eratosthenes(ll n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (ll p = 2; p * p <= n; p++) { if (is_prime[p]) { for (ll i = p * p; i <= n; i += p) { is_prime[i] = false; } } } for (ll i = 2; i <= n; i++) { if (is_prime[i]) { prime.pb(i); } } }

void execute() {
    string s;cin>>s;
    string ans=s;
    int h=s.size();
    for(int i=0;i<min(100,h);i++){
        ll ele=s[i]-'0',maxi=ele,pos=-1;
        for(int j=i+1;j<min(100,h);j++){
            ll t=(s[j]-'0')+(i)-j;
            if(maxi<t){
                pos=j;
                maxi=t;
            }
        }
        if(pos!=-1){
            for(int k=pos;k>=i+1;k--){
                swap(s[k],s[k-1]);
            }
            s[i]=maxi+'0';
        }
    }
    cout<<s<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll Testcases;
    cin >> Testcases;

    while (Testcases--) {
        execute();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    for(int i = 1; i <= n; i++) cout << d[i] << " ";
    cout << endl;
        cout << mx << endl;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    //for(int i = 1; i <= n; i++) cout << d[i] << " ";
    //cout << endl;
        cout << mx << endl;
    }
}


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

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    v.clear();
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        v.pb(max((ll)d[edg[a][i]],(ll)edg[edg[a][i]].size()));
    }
    sort(v.begin(),v.end());
    if(v.size() > 2){
        mx = max(mx,v[v.size() - 1] + v[v.size() - 2] + 1 - 2);
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    //for(int i = 1; i <= n; i++) cout << d[i] << " ";
    //cout << endl;
        cout << mx << endl;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    for(int i = 1; i <= n; i++) cout << d[i] << " ";
    cout << endl;
        cout << mx << endl;
    }
}


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

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    //for(int i = 1; i <= n; i++) cout << d[i] << " ";
    //cout << endl;
        cout << mx << endl;
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

#define all(v) v.begin(), v.end()
#define debug(x) cout << #x << '=' << x << endl;
#define pb push_back
#define int long long
const long long M = 998244353;

void solve(){
    int n; cin>>n;

    vector<vector<int>> vec(n+1);
    unordered_set<int> st;
    for(int i = 1; i <n; i++){
        int a, b; cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
        st.insert((a*1e6+b));
        st.insert((b*1e6+a));
    }
    if(n<=4){
        cout<<n-2<<endl;
        return;
    }

    vector<pair<int, int>> sz;
    for(int i = 1; i <=n; i++){
        sz.push_back({vec[i].size(), i});
    }
    sort(sz.rbegin(), sz.rend());

    for(int i = 1; i <n; i++){
        if(sz[i].first < sz[1].first){
            break;
        }
        if(st.count((sz[0].second*1e6+ sz[i].second)) == 0){
            cout<<sz[0].first+ sz[i].first-1<<endl;
            return;
        }
    }

    cout<<sz[0].first+ sz[1].first-2<<endl;

}

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

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

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define debug(x) cout << #x << '=' << x << endl;
#define pb push_back
#define int long long
const long long M = 998244353;

void solve(){
    int n; cin>>n;

    vector<vector<int>> vec(n+1);
    unordered_set<int> st;
    for(int i = 1; i <n; i++){
        int a, b; cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
        st.insert((a*1e6+b));
        st.insert((b*1e6+a));
    }
    if(n<=4){
        cout<<n-2<<endl;
        return;
    }

    vector<pair<int, int>> sz;
    for(int i = 1; i <=n; i++){
        sz.push_back({vec[i].size(), i});
    }
    sort(sz.begin(), sz.end());

    for(int i = n-2; i >=0; i--){
        if(sz[i].first < sz[n-2].first){
            break;
        }
        if(st.count((sz[n-1].second*1e6 + sz[i].second)) == 0){
            cout<<sz[n-1].first+ sz[i].first-1<<endl;
            return;
        }
    }

    cout<<sz[n-1].first+ sz[n-2].first-2<<endl;

}

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

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

    return 0;
}