ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

#define ll long long
#define ld long double
#define INF 9

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        for (int i = 0; i < n + 2; i++) {
            for (int j = 0; j < m + 2; j++) {
                cout << dp[i][j] << " ";
            }
            cout << "\n";
        }
        cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        for (int i = 0; i < n + 2; i++) {
            for (int j = 0; j < m + 2; j++) {
                cout << dp[i][j] << " ";
            }
            cout << "\n";
        }
        cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


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

#define ll long long
#define ld long double
#define INF 9

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "-" + a;
        b = "-" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

int dp[1001][1001];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}

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

int dp[1001][1001];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1001; i++)
            for (j = 0; j < 1001; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

int dp[1000][1000];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}

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

int dp[1001][1001];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


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

// dp[i][j] = minimum number of replacements at position a[i], b[j], c[i + j]
int dp[1000][1000];

int f(string a, string b, string c, int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(a, b, c, i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(a, b, c, i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    string a, b, c;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(a, b, c, 0, 0) << '\n';
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

// dp[i][j] = minimum number of replacements at position a[i], b[j], c[i + j]
int dp[1000][1000];

int f(string a, string b, string c, int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(a, b, c, i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(a, b, c, i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    string a, b, c;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(a, b, c, 0, 0) << '\n';
    }
    return 0;
}

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

int dp[1000][1000];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1000; i++)
            for (j = 0; j < 1000; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]<v[j]){
                vp.push_back({v[j],v[i]});
                vp.push_back({v[i],v[j]});
            }
        }
    }

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
            }
        }
    }
    for (int i = n-1; i >=0; i--)
    {
        for (int j = i; j >=0; j--)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
                vp.push_back({v[j],v[i]});
            }
        }
    }

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]<v[j]){
                vp.push_back({v[j],v[i]});
                vp.push_back({v[i],v[j]});
            }
        }
    }

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
            }
        }
    }
    for (int i = n-1; i >=0; i--)
    {
        for (int j = i; j >=0; j--)
        {
            if(v[i]>v[j]){
                vp.push_back({v[i],v[j]});
                vp.push_back({v[j],v[i]});
            }
        }
    }

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    
    for (int i = 0; i < n; i++)
    {
        for (int j = n-2; j >=i; j--)
        {
            if(v[j]<v[j+1]){
                vp.push_back({v[j],v[j+1]});
                swap(v[j],v[j+1]);
            }
            
        }
    }

    for(int i=0;i<n;i++){
        for(int j = n-2;j>=i;j--){
            if(v[j]>v[j+1]){
                vp.push_back({v[j],v[j+1]});
            }
        }
    }

    // for(auto & x : v){
    //     cout<<x<<" ";
    // }
    // cout<<"\n";

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    
    for (int i = 0; i < n; i++)
    {
        for (int j = n-2; j >=i; j--)
        {
            if(v[j]<v[j+1]){
                vp.push_back({v[j],v[j+1]});
                swap(v[j],v[j+1]);
            }
            
        }
    }

    for(int i=0;i<n;i++){
        for(int j = n-2;j>=i;j--){
            if(v[j]>v[j+1]){
                vp.push_back({v[j],v[j+1]});
            }
        }
    }

    // for(auto & x : v){
    //     cout<<x<<" ";
    // }
    // cout<<"\n";

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ffl(i, a, b) for (int i = a; i < b; i++)
#define ffu(i, a, b) for (int i = a; i <= b; i++)
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<pair<int,int>>vp;
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <n-1-i; j++)
        {
            if(v[j]<v[j+1]){
                vp.push_back({v[j],v[j+1]});
                swap(v[j],v[j+1]);
            }
            
        }
    }

    for(int i=0;i<n;i++){
        for(int j = 0; j <n-1-i; j++){
            if(v[j]>v[j+1]){
                vp.push_back({v[j],v[j+1]});
                swap(v[j],v[j+1]);
            }
        }
    }

    // for(auto & x : v){
    //     cout<<x<<" ";
    // }
    // cout<<"\n";
    reverse(vp.begin(),vp.end());

    cout<<vp.size()<<"\n";
    for(auto & x : vp){
        cout<<x.first<<" "<<x.second<<"\n";
    }
    cout<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

template<typename T> void ckmin(T &x, T y) {if (y < x) x = y;}
template<typename T> void ckmax(T &x, T y) {if (y > x) x = y;}

void solve() {
    int n;
    cin >> n;
    
    vector<vector<int> > adjList(n + 5);
    int deg[n + 5] = {};

    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }

    multiset<int> ms;
    for (int i = 1; i <= n; i ++)
        ms.insert(deg[i]);

    int ans = 0;
    
    for (int u = 1; u <= n; u++) {
        for (int v : adjList[u]) ckmax(ans, deg[u] + deg[v] - 2);
        
        ms.erase(deg[u]);
        for (int v : adjList[u]) ms.erase(deg[v]);
        if (ms.size()) ckmax(ans, deg[u] + *ms.rbegin() - 1);
        ms.insert(deg[u]);
        for (int v : adjList[u]) ms.insert(deg[v]);
    }

    cout << ans << '\n';
}

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

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

template<typename T> void ckmin(T &x, T y) {if (y < x) x = y;}
template<typename T> void ckmax(T &x, T y) {if (y > x) x = y;}

void solve() {
    int n;
    cin >> n;
    
    vector<vector<int> > adjList(n + 5);
    int deg[n + 5] = {};

    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }

    multiset<int> ms;
    for (int i = 1; i <= n; i ++)
        ms.insert(deg[i]);

    int ans = 0;
    
    for (int u = 1; u <= n - 1; u++) {
        for (int v : adjList[u]) ckmax(ans, deg[u] + deg[v] - 2);

        ms.erase(ms.find(deg[u]));
        for (int v : adjList[u]) ms.erase(ms.find(deg[v]));

        if (ms.size()) ckmax(ans, deg[u] + *ms.rbegin() - 1);
        ms.insert(deg[u]);
        for (int v : adjList[u]) ms.insert(deg[v]);
    }

    cout << ans << '\n';
}

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