ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        if(sum%9==0) cout<<"YES\n";

        else{

            int d = 9 - sum%9;

            if(d%2!=0) d+=9;

            // cout<<d<<" "<<two*2 + three*6<<endl;

            if(two*2 + three*6 >=d  ){

                d = d - two*2;

                if(d>0 &&d%6!=0 )

                cout<<"NO\n";

                else if(d>0 && d%6==0 && d/6 > three){

                    cout<<"NO\n";

                }

                else

                cout<<"YES\n";

            }

            else{

                cout<<"NO\n";

            }

            

        }

        

    }

    return 0;

}

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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        int flag=0;

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

            for(int j=0;j<=three;j++){

                if((sum+i*2+j*6)%9==0){

                    flag++;

                    break;

                }

            }

        }

        if(flag) cout<<"YES\n";

        else{

            cout<<"NO\n";

        }      

        }

        

    

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        if(sum%9==0) cout<<"YES\n";

        else{

            int d = 9 - sum%9;

            if(d%2!=0) d+=9;

            // cout<<d<<" "<<two*2 + three*6<<endl;

            if(two*2 + three*6 >=d  ){

                d = d - two*2;

                if(d>0 &&d%6!=0 )

                cout<<"NO\n";

                else if(d>0 && d%6==0 && d/6 < three){

                    cout<<"NO\n";

                }

                else

                cout<<"YES\n";

            }

            else{

                cout<<"NO\n";

            }

            

        }

        

    }

    return 0;

}

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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        if(sum%9==0) cout<<"YES\n";

        else{

            int d = 9 - sum%9;

            if(d%2!=0) d+=9;

            // cout<<d<<" "<<two*2 + three*6<<endl;

            if(two*2 + three*6 >=d  ){

                d = d - two*2;

                if(d>0 &&d%6!=0 )

                cout<<"NO\n";

                else if(d>0 && d%6==0 && d/6 > three){

                    cout<<"NO\n";

                }

                else

                cout<<"YES\n";

            }

            else{

                cout<<"NO\n";

            }

            

        }

        

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        if(sum%9==0) cout<<"YES\n";

        else{

            int d = 9 - sum%9;

            if(d%2!=0) d+=9;

            // cout<<d<<" "<<two*2 + three*6<<endl;

            if(two*2 + three*6 >=d  ){

                d = d - two*2;

                if(d>=0 &&d%6!=0 )

                cout<<"NO\n";

                else if(d>=0 && d%6==0 && d/6 < three){

                    cout<<"NO\n";

                }

                else

                cout<<"YES\n";

            }

            else{

                cout<<"NO\n";

            }

            

        }

        

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r=0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = ll(a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	ll yu = 9 - r;

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

}

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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r = 0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = ll(a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r=0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = ll(a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	ll yu = 9 - r;

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r = 0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = ll(a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

}

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

using namespace std;

#define ll long long

void fun()

{

	string a;

	cin >> a;

	ll len = a.size();

	ll r = 0;

	ll a2 = 0, a3 = 0;

	for (ll i = 0; i < len; i++)

	{

		ll tem = (a[i] - '0');

		if (tem == 2)a2++;

		if (tem == 3)a3++;

		r += tem;

		r %= 9;

	}

	for (ll i = 0; i <= a2; i++)

	{

		for (ll j = 0; j <= a3; j++)

		{

			ll tem = i * 2 + j * 6;

			tem += r;

			if (tem % 9 == 0)

			{

				cout << "YES" << endl;

				return;

			}

		}

	}

	cout << "NO" << endl;

}

int main()

{

	int o;

	cin >> o;

	while (o--)

	{

		fun();

	}

}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  for (int c = n; c > 1; c--) {
    vector<int> b(c - 1);
    for (int i = 0; i + 1 < c; i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = b;
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  while (a.size() > 1) {
    vector<int> b(a.size() - 1);
    for (int i = 0; i < b.size(); i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = move(b);
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  while (a.size() > 1) {
    vector<int> b(a.size() - 1);
    for (int i = 0; i < b.size(); i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = move(b);
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<i64> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  while (a.size() > 1) {
    vector<i64> b(a.size() - 1);
    for (int i = 0; i < b.size(); i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = move(b);
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  for (int c = n; c > 1; c--) {
    vector<int> b(c - 1);
    for (int i = 0; i + 1 < c; i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = move(b);
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  for (int c = n; c > 1; c--) {
    vector<int> b(c - 1);
    for (int i = 0; i + 1 < c; i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = b;
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  for (int c = n; c > 1; c--) {
    vector<int> b(c - 1);
    for (int i = 0; i + 1 < c; i++) {
      b[i] = a[i] - a[i + 1];
    }
    i64 sum = accumulate(b.begin(), b.end(), 0LL);
    ans = max(ans, abs(sum));
    a = move(b);
  }
  cout << ans << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (1 << i) - 1 << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (1 << i) - 1 << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                        }
                    }
                }
            }
        }
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (1 << i) - 1 << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (1 << i) - 1 << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                        }
                    }
                }
            }
        }
    }
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                        }
                    }
                }
            }
        }
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                        }
                    }
                }
            }
        }
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            int z = 0;
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << z + (1 << i) << ' ' << z + (1 << i) - 1 << ' ' << z + (l == (1 << i) - 1 ? r : l) << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                            z += (1 << i);
                        }
                    }
                }
            }
        }
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

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

    int t;
    cin >> t;

    while (t--) {
        ll n;
        cin >> n;
        vector<vector<ll>> adj(n);
        set<pair<ll, ll>> s;

        for (int i = 0; i < n - 1; i++) { 
            ll a, b;
            cin >> a >> b;
            a--; 
            b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        if (n == 2) {
            cout << 0 << endl;
            continue;
        }

        for (int i = 0; i < n; i++) {
            s.insert({adj[i].size(), i});
        }

        int maxi = INT_MIN;

        for (int i = 0; i < n; i++) {
            set<pair<ll, ll>> temp = s;
             temp.erase({adj[i].size(),i});
            for (auto x : adj[i]) {
                maxi = max(maxi, (int)(adj[i].size() + adj[x].size() - 1));
                temp.erase({adj[x].size(), x});
            }

            if (!temp.empty()) {
                auto maxElement = *temp.rbegin(); 
                maxi = max(maxi, (int)(adj[i].size() + maxElement.first));
            }
           
        }

       cout << maxi - 1 << endl;
    }

    return 0;
}


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

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

    int t;
    cin >> t;

    while (t--) {
        ll n;
        cin >> n;
        vector<vector<ll>> adj(n);
        set<pair<ll, ll>> s;

        for (int i = 0; i < n - 1; i++) { 
            ll a, b;
            cin >> a >> b;
            a--; 
            b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        if (n == 2) {
            cout << 0 << endl;
            continue;
        }

        for (int i = 0; i < n; i++) {
            s.insert({adj[i].size(), i});
        }

        int maxi = INT_MIN;

        for (int i = 0; i < n; i++) {
            
             s.erase({adj[i].size(),i});
            for (auto x : adj[i]) {
                maxi = max(maxi, (int)(adj[i].size() + adj[x].size() - 1));
                s.erase({adj[x].size(), x});
            }

            if (!s.empty()) {
                auto maxElement = *s.rbegin(); 
                maxi = max(maxi, (int)(adj[i].size() + maxElement.first));
            }
            for (auto x : adj[i]) {
               
                s.insert({adj[x].size(), x});
            }
            s.insert({adj[i].size(),i});
            
           
        }

       cout << maxi - 1 << endl;
    }

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


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

ll f(vector<vector<ll>>& adj, ll node, ll count, ll n, ll pre) {
    if (count == 0) {
        return 0;
    }
    if (node >= n) {
        return 0;
    }

    ll rem = 0, notrem = 0;

    if (pre == -1) {
        rem = adj[node].size() + f(adj, node + 1, count - 1, n, node);
    } else {
        rem = adj[node].size();
        if (find(adj[node].begin(), adj[node].end(), pre) != adj[node].end()) {
            rem--;
        }
        rem += f(adj, node + 1, count - 1, n, node);
    }

    notrem = f(adj, node + 1, count, n, pre);
    return max(rem, notrem);
}

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

    int t;
    cin >> t;

    while (t--) {
        ll n;
        cin >> n;
        vector<vector<ll>> adj(n);

        for (int i = 0; i < n - 1; i++) { 
            ll a, b;
            cin >> a >> b;
            a--;
            b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        if (n == 2) {
            cout << 0 << endl;
            continue;
        }

        cout << f(adj, 0, 2, n, -1)-1 << endl;
    }

    return 0;
}