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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;

string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+10,vector<int>(b.size()+10));
    for (size_t i = 0; i < a.size()+10; i++)
    {
        for (size_t j = 0; j < b.size()+10; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    dp[0][0] = 0;
 

    for (size_t i = 1; i <= a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

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

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;

string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+10,vector<int>(b.size()+10));
    for (size_t i = 0; i < a.size()+10; i++)
    {
        for (size_t j = 0; j < b.size()+10; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    dp[0][0] = 0;
 

    for (size_t i = 1; i <= a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        
    }
    for (size_t i = 1; i <= b.size(); i++)
    {
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>t;
while(t--){
    solve();
}
return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;
struct zt
{
    int count;
    int a_idx;
    int b_idx;
};
string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+2,vector<int>(b.size()+2));
    for (size_t i = 0; i < a.size()+2; i++)
    {
        for (size_t j = 0; j < b.size()+2; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    int ans1 = 0,ans0 = 0;
    dp[1][0] = 1;
    dp[0][1] = 1;
    if (a[0] == c[0]){
        dp[1][0] = 0;

    }
    if (b[0] ==c[0]) dp[0][1] = 0;
    for (size_t i = 2; i < a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

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

Submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;

string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+2,vector<int>(b.size()+2));
    for (size_t i = 0; i < a.size()+2; i++)
    {
        for (size_t j = 0; j < b.size()+2; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    dp[0][0] = 0;
 

    for (size_t i = 1; i <= a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>t;
while(t--){
    solve();
}
return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;

string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+2,vector<int>(b.size()+2));
    for (size_t i = 0; i < a.size()+2; i++)
    {
        for (size_t j = 0; j < b.size()+2; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    dp[0][0] = 0;
 

    for (size_t i = 1; i <= a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

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

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define N 100005
#define MOD (1e9+7)
int t,n;

string a,b,c;
void solve(){
    cin>>a>>b>>c;
    vector<vector<int>>dp(a.size()+10,vector<int>(b.size()+10));
    for (size_t i = 0; i < a.size()+10; i++)
    {
        for (size_t j = 0; j < b.size()+10; j++)
        {
            dp[i][j] = INT_MAX;
        }
        
    }
    
    dp[0][0] = 0;
 

    for (size_t i = 1; i <= a.size(); i++)
    {
        if (a[i-1] == c[i-1]){dp[i][0]=dp[i-1][0];}
        else{dp[i][0]=dp[i-1][0]+1;}
        if (b[i-1] == c[i-1]){dp[0][i]=dp[0][i-1];}
        else{dp[0][i]=dp[0][i-1]+1;}
    }
    
    
    
    for (size_t i = 1; i <= a.size(); i++)
    {
        for (size_t j = 1; j <= b.size(); j++)
        {
            dp[i][j] = min(dp[i-1][j]+(int)(a[i - 1] != c[i + j - 1]),dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));

        }
        
    }
    cout<<dp[a.size()][b.size()]<<endl;
    

}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>t;
while(t--){
    solve();
}
return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ve vector
#define fi first
#define se second
#define pb push_back
#define pll pair<int,int>
#define AC cout << "\n---------------------\n";
#define vi vector<int>
#define vii vector<vi>
//srand((unsigned int)time(NULL));        rand();
const double eps = 1e-6;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
const int mod = 998244353;
const int inf = 1e18;
void solve() {
    int n, m;
    cin >> n >> m;
    vi a1(n + 1);
    vi a2(m + 1);
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++)cin >> a1[i], sum1 += a1[i];
    for (int i = 1; i <= m; i++)cin >> a2[i], sum2 += a2[i];
    vi vis2(m + 1);
    vi vis1(n + 1);
    if (sum1 != sum2){
        cout << "NO\n";
        return ;
    }
    sort(a1.begin(), a1.end());
    sort(a2.begin(), a2.end());
    int p1 = 1;
    for (int i = 1; i <= m; i++){
        while (a1[p1] < a2[i] && p1 + 1 <= n)p1++;
        if (a1[p1] == a2[i]){
            p1++;
            vis1[p1] = 1;
            vis2[i] = 1;
        }
    }
    multiset<int> s1, s2;
    for (int i = 1; i <= n; i++){
        if (vis1[i] == 0)s1.insert(a1[i]);
    }
    for (int i = 1; i <= m; i++){
        if (vis2[i] == 0)s2.insert(a2[i]);
    }
    while (s2.size()){
        while(s1.size() && *s1.begin() == *s2.begin()){
            s1.erase(s1.begin());
            s2.erase(s2.begin());
        }
        if (s2.size() == 0)break;
        if (*s1.begin() > *s2.begin()){
            break;
        }
        int x = *s1.begin();
        s1.erase(s1.begin());
        int y = *s1.begin();
        s1.erase(s1.begin());
        if (abs(x - y) > 1){
            break;
        }
        s1.insert(x + y);
    }
    cout << (s2.size() == 0 ? "YES\n" : "NO\n");
}
/*

*/
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);// getline()前请使用cin.ignore();  或者关闭ios 启动getchar()
    int t1 = 1;
    cin >> t1;
    while (t1--){
        solve();
    }
    return 0;
}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#pragma optimize GCC(2)

#pragma optimize GCC(3)

#pragma optimize GCC("Ofast")

#include <bits/stdc++.h>

#define endl '\n'

// #define int long long

#define lowbit(x) x & -x

using i64 = long long;

using u64 = unsigned long long;

using ld = long double;

const int maxn = 2e5 + 5;

const int inf = 0x7f7f7f7f;

const int mod = 1e9 + 7;



struct custom_hash 

{

	static uint64_t splitmix64(uint64_t x)

    {

		x ^= x << 13;

		x ^= x >> 7;

		x ^= x << 17;

		return x; 

	}

	size_t operator () (uint64_t x) const 

    {

		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳

		return splitmix64(x + FIXED_RANDOM);

	}

};

char ch[550];

void solve()

{

    int n = 0;

    std::cin >> n;

    for (int i = 1; i <= n; i++) std::cin >> ch[i];

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

    {

        if (ch[i] == 's')

        {

            if (i == 1 || i == n) continue;

            for (int j = 1; j <= n; j++)

            {

                if (ch[j] == 'p')

                {

                    if (j < i)

                    {

                        std::cout << "NO" << endl;

                        return;

                    }

                    else

                    {

                        int lenj = j, leni = n - i + 1;

                        int len = std::min(lenj, leni);

                        if (len > abs(j - i + 1))

                        {

                            std::cout << "NO" << endl;

                            return;

                        }

                    }

                }

            }

        }

    }

    std::cout << "YES" << endl;

}



signed main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr); std::cout.tie(nullptr);

    //freopen("out.txt", "w", stdout);

    int t = 1;

    std::cin >> t;

    while(t--)

    {

        solve();

    }

    return 0;

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

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

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int dx[] = { 1, -1, 0 , 0 };
int dy[] = { 0, 0, 1 , -1 };

const int OO = (1 << 30), MOD = 1e9 + 7;
const ll OOLL = (1ll << 60);

const int N=1e5+7, M=5e3, MAXLOG=25;

ll add(ll a, ll b)
{
    return ((a % MOD) + (b % MOD)) % MOD;
}

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;

    vector<ll> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(all(a));

    ll t = 0;
    for(int i = 0; i < (r - l +1 ); i++)
        t+= a[i];

        cout << t << endl;
    

}

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


    int t = 1;
    cin >> t;

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

    return 0;
}

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

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int dx[] = { 1, -1, 0 , 0 };
int dy[] = { 0, 0, 1 , -1 };

const int OO = (1 << 30), MOD = 1e9 + 7;
const ll OOLL = (1ll << 60);

const int N=1e5+7, M=5e3, MAXLOG=25;

ll add(ll a, ll b)
{
    return ((a % MOD) + (b % MOD)) % MOD;
}

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;

    vector<ll> pre, mid, last;
    ll total = 0;  
    for (size_t i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if(i < l){
            pre.push_back(x);
        }else if( i <= r){
            mid.push_back(x);
            total += x;
        }else{
            last.push_back(x);
        }
    }

    sort(all(pre));
    sort(all(last));

    sort(all(mid));
    reverse(all(mid));
    
    int i = 0, j = 0;
    ll t = total;
    while(i < pre.size() && j < mid.size()){
        if(pre[i] < mid[j]){
            t -= mid[j];
            t += pre[i];
            i++;
            j++;
        }else{
            break;
        }
    }

    i = 0; j = 0;
    ll t2 = total;
    while(i < last.size() && j < mid.size()){
        if(last[i] < mid[j]){
            t2 -= mid[j];
            t2 += last[i];
            i++;
            j++;
        }else{
            break;
        }
    }

    cout << min(t, t2) << endl;
}

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


    int t = 1;
    cin >> t;

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

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

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

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int dx[] = { 1, -1, 0 , 0 };
int dy[] = { 0, 0, 1 , -1 };

const int OO = (1 << 30), MOD = 1e9 + 7;
const ll OOLL = (1ll << 60);

const int N=1e5+7, M=5e3, MAXLOG=25;

ll add(ll a, ll b)
{
    return ((a % MOD) + (b % MOD)) % MOD;
}

void solve() {
    int n, l, r;
    cin >> n >> l >> r;

    vector<int> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(all(a));

    int t = 0;
    for(int i = 0; i < (r - l +1 ); i++)
        t+= a[i];

        cout << t << endl;
    

}

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


    int t = 1;
    cin >> t;

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

    return 0;
}

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

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int dx[] = { 1, -1, 0 , 0 };
int dy[] = { 0, 0, 1 , -1 };

const int OO = (1 << 30), MOD = 1e9 + 7;
const ll OOLL = (1ll << 60);

const int N=1e5+7, M=5e3, MAXLOG=25;

ll add(ll a, ll b)
{
    return ((a % MOD) + (b % MOD)) % MOD;
}

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;

    vector<ll> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(all(a));

    ll t = 0;
    for(int i = 0; i < (r - l +1 ); i++)
        t+= a[i];

        cout << t << endl;
    

}

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


    int t = 1;
    cin >> t;

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

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


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

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int dx[] = { 1, -1, 0 , 0 };
int dy[] = { 0, 0, 1 , -1 };

const int OO = (1 << 30), MOD = 1e9 + 7;
const ll OOLL = (1ll << 60);

const int N=1e5+7, M=5e3, MAXLOG=25;

ll add(ll a, ll b)
{
    return ((a % MOD) + (b % MOD)) % MOD;
}

void solve() {
    int n, l, r;
    cin >> n >> l >> r;

    vector<int> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(all(a));

    int t = 0;
    for(int i = 0; i < (r - l +1 ); i++)
        t+= a[i];

        cout << t << endl;
    

}

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


    int t = 1;
    cin >> t;

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

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


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    set<int> adj[n+1];
    int deg[n+1] = {};
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
        deg[u]++;
        deg[v]++;
    }
    int mx = 0, idx = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    int ans = mx-1;
    for (auto &i : adj[idx]) {
        adj[i].erase(idx);
        deg[i]--;
    }
    int j = idx;
    mx = 0, idx = 0;
    for (int i = 0; i < n; i++) {
        if (i == j) continue;
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    ans += mx;
    cout << ans << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    set<int> adj[n+1];
    int deg[n+1] = {};
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
        deg[u]++;
        deg[v]++;
    }
    int mx = 0, idx = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    int ans = mx-1;
    for (auto &i : adj[idx]) {
        adj[i].erase(idx);
        deg[i]--;
    }
    int j = idx;
    mx = 0, idx = 0;
    for (int i = 0; i < n; i++) {
        if (i == j) continue;
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    ans += mx;
    cout << ans << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    set<int> adj[n+1];
    int deg[n+1] = {};
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
        deg[u]++;
        deg[v]++;
    }
    int mx = 0, idx = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    int ans = mx;
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == idx) continue;
        if (adj[i].find(idx) != adj[i].end()) mx = max(mx, ans+deg[i]-2);
        else mx = max(mx, ans+deg[i]-1);
    }
    cout << mx << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);   
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    set<int> adj[n+1];
    int deg[n+1] = {};
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
        deg[u]++;
        deg[v]++;
    }
    int mx = 0, idx = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] > mx) {
            mx = deg[i];
            idx = i;
        }
    }
    int ans = mx;
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == idx) continue;
        if (adj[i].find(idx) != adj[i].end()) mx = max(mx, ans+deg[i]-2);
        else mx = max(mx, ans+deg[i]-1);
    }
    cout << mx << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);   
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    vi adj[n+1];
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    multiset<int> st;
    for (int i = 1; i <= n; i++) st.insert(adj[i].size());
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (auto &j : adj[i]) {
            int mx = adj[i].size() + adj[j].size() - 2;
            ans = max(ans, mx);
            st.erase(st.find(adj[j].size()));
        }
        st.erase(st.find(adj[i].size()));
        if (!st.empty()) {
            int mx = adj[i].size() + *st.rbegin() - 1;
            ans = max(ans, mx);
        }
        for(auto &j : adj[i]){
            st.insert(adj[j].size());
        }
        st.insert(adj[i].size());
    }
    cout << ans << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);   
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


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

#define ll long long
#define vtr vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define arg sort(v.begin(),v.end())
#define Lrg sort(v.rbegin(),v.rend())
#define lm(a,b) for(int i=a; i<b; i++)
#define tst int t; cin >> t; while(t--)
#define nl

using namespace std;
void slayer()
{
    ll r,l;
    cin >> r >> l;
    ll pos;
    for(int i=30; i>=0; i--){
        if((l&(1LL<<i))!=(r&(1LL<<i))){
            pos=i;
            break;
        }
    }
    ll a=l|(1LL<<pos)-1;
    ll b=a+1;
    ll c=r;
    if(c==a || c==b)c--;
    if(c==a || c==b)b--;
    cout << a << " " << b << " " << c << endl;
}
int main()
{
    tst{
        slayer();
    }

    return 0;
}