ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

using namespace std;

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

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

  ll mx_val=0, mx=0;
  for (ll i=0; i<n; ++i) {
    if (adj[i].size() > mx_val) {
      mx=i;
      mx_val=adj[i].size();
    }
  }
  ll mx_val2=0, mx2=0;
  for (ll i=0; i<n; ++i) {
    if (i==mx) continue;
    ll degrees=adj[i].size()-adj[i].count(mx);
    if (degrees>mx_val2) {
      mx_val2=degrees;
      mx2=i;
    }
  }

  cout << mx_val + mx_val2 - 1 << "\n";
}

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

  ll t=1;
  cin >> t;

  while (t--)
    solve();
}


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

using namespace std;

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

  vector<set<int>> adj(n);
  for (int i=0; i<n-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  vector<pair<int, int>> degrees; // first is degree, second is the noded
  for (int i=0; i<n; ++i) {
    degrees.push_back({adj[i].size(), i});
  }
  sort(rbegin(degrees), rend(degrees));

  if (n==2) {
    cout << 0 << "\n";
    return;
  }

  int mx_val=degrees[0].first, mx_node=degrees[0].second;
  if (degrees[0].first==degrees[1].first && degrees[1].first==degrees[2].first) {
    for (int i=0; i<2; ++i) {
      int node=degrees[i].second;
      int node2=degrees[(i+1)%3].second;
      int node3=degrees[(i+2)%3].second;
      if (adj[node].count(node2)==0 || adj[node].count(node3)==0) {
        mx_node=node;
        break;
      }
    }
  }

  int mx_val2=0;
  for (int i=0; i<n; ++i) {
    if (i==mx_node) continue;
    int cnt=adj[i].size() - adj[i].count(mx_node);
    if (cnt>mx_val2) {
      mx_val2=cnt;
    }
  }
  cout << mx_val + mx_val2 - 1 << "\n";
}

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

  ll t=1;
  cin >> t;

  while (t--)
    solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

using namespace std;

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

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

  int mx_val=0, mx=0;
  for (int i=0; i<n; ++i) {
    if (adj[i].size() > mx_val) {
      mx=i;
      mx_val=adj[i].size();
    }
  }
  int mx_val_2=0, mx2=0;
  for (int i=0; i<n; ++i) {
    if (i==mx) continue;
    int cnt=adj[i].size()-adj[i].count(mx);
    if (cnt>mx_val_2) {
      mx2=i;
      mx_val_2=cnt;
    }
  }

  cout << mx_val + mx_val_2 - 1 - adj[mx2].count(mx)  << "\n";
}

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

  int t=1;
  cin >> t;

  while (t--)
    solve();
}


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

using namespace std;

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

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

  ll mx_val=0, mx=0;
  for (ll i=0; i<n; ++i) {
    if (adj[i].size() > mx_val) {
      mx=i;
      mx_val=adj[i].size();
    }
  }
  ll mx_val2=0, mx2=0;
  for (ll i=0; i<n; ++i) {
    if (i==mx) continue;
    ll degrees=adj[i].size()-adj[i].count(mx);
    if (degrees>mx_val2) {
      mx_val2=degrees;
      mx2=i;
    }
  }

  cout << mx_val + mx_val2 - 1 << "\n";
}

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

  ll t=1;
  cin >> t;

  while (t--)
    solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    
    int t;
    cin>>t;
    while(t--) {
        int n,k;
        cin>>n>>k;
        vector<int> v(n);
        for(int i=0;i<n;i++) {
            cin>>v[i];
        }
        sort(v.begin(),v.end());

        vector<int> g;

        int ans=1;
        int t=1;
        for(int i=1;i<n;i++) {
            if(v[i]==v[i-1]) {
                t++;
            } else {
                g.push_back(t);
                t=1;
                ans++;
            }
            if(i==n-1) {
                g.push_back(t);
            }
        }

        sort(g.begin(),g.end());

        for(int i=0;i<n-1;i++) {
            if(k>=g[i]) {
                k-=g[i];
                ans--;
            }else {
                break;
            }
        }

        cout<<ans<<endl;
    }



}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    // txt
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());

        vector<int> g;

        int t = 1;
        for (int i = 1; i < n; i++) {
            if (v[i] == v[i - 1]) {
                t++;
            } else {
                g.push_back(t);
                t = 1;
            }
            if (i == n - 1) {
                g.push_back(t);
            }
        }
        int ans = g.size();

        sort(g.begin(), g.end());

        for (int i = 0; i < n - 1; i++) {
            if (k >= g[i]) {
                k -= g[i];
                ans--;
            } else {
                break;
            }
        }

        cout << ans << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    // txt
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());

        vector<int> g;

        int t = 1;
        for (int i = 1; i < n; i++) {
            if (v[i] == v[i - 1]) {
                t++;
            } else {
                g.push_back(t);
                t = 1;
            }
            if (i == n - 1) {
                g.push_back(t);
            }
        }
        int ans = g.size();

        sort(g.begin(), g.end());

        for (int i = 0; i < n - 1; i++) {
            if (k >= g[i]) {
                k -= g[i];
                ans--;
            } else {
                break;
            }
        }

        cout << ans << endl;
    }
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    // txt
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        sort(v.begin(), v.end());

        vector<int> g;

        int t = 1;
        for (int i = 1; i < n; i++) {
            if (v[i] == v[i - 1]) {
                t++;
            } else {
                g.push_back(t);
                t = 1;
            }
            if (i == n - 1) {
                g.push_back(t);
            }
        }
        int ans = g.size();

        sort(g.begin(), g.end());

        for (int i = 0; i < n - 1; i++) {
            if (k >= g[i]) {
                k -= g[i];
                ans--;
            } else {
                break;
            }
        }

        cout << max(ans,(int)1) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    // txt
    int t;
    cin>>t;
    while(t--) {
        int n,k;
        cin>>n>>k;
        vector<int> v(n);
        for(int i=0;i<n;i++) {
            cin>>v[i];
        }
        sort(v.begin(),v.end());

        vector<int> g;

        int ans=1;
        int t=1;
        for(int i=1;i<n;i++) {
            if(v[i]==v[i-1]) {
                t++;
            } else {
                g.push_back(t);
                t=1;
                ans++;
            }
            if(i==n-1) {
                g.push_back(t);
            }
        }

        sort(g.begin(),g.end());

        for(int i=0;i<n-1;i++) {
            if(k>=g[i]) {
                k-=g[i];
                ans--;
            }else {
                break;
            }
        }

        cout<<ans<<endl;
    }



}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    // txt
    int t;
    cin>>t;
    while(t--) {
        int n,k;
        cin>>n>>k;
        vector<int> v(n);
        for(int i=0;i<n;i++) {
            cin>>v[i];
        }
        sort(v.begin(),v.end());

        vector<int> g;

        int ans=1;
        int t=1;
        for(int i=1;i<n;i++) {
            if(v[i]==v[i-1]) {
                t++;
            } else {
                g.push_back(t);
                t=1;
                ans++;
            }
            if(i==n-1) {
                g.push_back(t);
            }
        }

        sort(g.begin(),g.end());

        for(int i=0;i<n-1;i++) {
            if(k>=g[i]) {
                k-=g[i];
                ans--;
            }else {
                break;
            }
        }

        cout<<ans<<endl;
    }



}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ordered_set tree < int, null_type,less <int >, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;


signed main() {
    
    int t;
    cin>>t;
    while(t--) {
        int n,k;
        cin>>n>>k;
        vector<int> v(n);
        for(int i=0;i<n;i++) {
            cin>>v[i];
        }
        sort(v.begin(),v.end());

        vector<int> g;

        int ans=1;
        int t=1;
        for(int i=1;i<n;i++) {
            if(v[i]==v[i-1]) {
                t++;
            } else {
                g.push_back(t);
                t=1;
                ans++;
            }
            if(i==n-1) {
                g.push_back(t);
            }
        }

        sort(g.begin(),g.end());

        for(int i=0;i<n-1;i++) {
            if(k>=g[i]) {
                k-=g[i];
                ans--;
            }else {
                break;
            }
        }

        cout<<ans<<endl;
    }



}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using lld = long double;
using ull = unsigned long long;

const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1e9 + 7;

#define ff first
#define ss second
#define pb push_back
#define fl(i, n) for (ll i = 0; i < n; i++)
#define py cout << "YES\n";
#define pm cout << "-1\n";
#define pn cout << "NO\n";
#define pimp cout << "IMPOSSIBLE\n";
#define all(x) (x).begin(), (x).end()
#define input(a, n) for (ll i = 0; i < n; i++) cin >> a[i]


ll solver(ll p1,ll p2,ll pos, string a, string b, string c,vector<vector<vector<ll>>>&dp){

    if(p1==a.size()){

        ll count=0;
        for(ll i=p2;i<b.size();i++){

            if(b[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(p2==b.size()){

        ll count=0;
        for(ll i=p1;i<a.size();i++){

            if(a[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(dp[p1][p2][pos]!=-1)return dp[p1][p2][pos];

    dp[p1][p2][pos]=1e9;

    if(a[p1]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    if(b[p2]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1,p2+1,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1,p2+1,pos+1,a,b,c,dp));

    }

    return dp[p1][p2][pos];
}

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

    ll t;
    cin >> t;

    while (t--) {
        
        string a,b,s;

        cin>>a>>b>>s;

        ll p1=a.size();

        ll p2=b.size();

        vector<vector<vector<ll>>>dp(p1+1,vector<vector<ll>>(p2+1,vector<ll>(p1+p2+1,-1)));


        solver(0ll , 0ll, 0ll, a, b, s, dp);

        cout<<dp[0][0][0]<<endl;
        
        
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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

using namespace std;

#define ll long long int

bool comp (pair<ll, int> a, pair<ll, int> b) {
    return a.second < b.second;
}

int main(){
    int t;
    cin>>t;
    for (int ii = 0;ii<t;ii++) {
        int n,k;
        cin>>n>>k;
        unordered_map<ll, int>values;
        for (int j = 0 ; j < n; j++) {
            ll e;
            cin>>e;
            if (values.find(e) == values.end()) values[e] = 0;
            values[e]+=1;
        }
        vector<pair<ll, int> > vals;
        for (auto it: values) vals.push_back(it);
        sort(vals.begin(), vals.end(), comp);
        int i = 0;
        while (i < vals.size()-1) {
            k-=vals[i].second;
            if (k < 0) break;
            i+=1;
        }
        cout<<vals.size()-i<<endl;

    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long int

bool comp (pair<ll, int> a, pair<ll, int> b) {
    return a.second < b.second;
}

int main(){
    int t;
    cin>>t;
    for (int ii = 0;ii<t;ii++) {
        int n,k;
        cin>>n>>k;
        if (k >= n-1){
            for (int j = 0 ; j < n; j++) {
                ll e;
                cin>>e;
            }
            cout <<"1"<<endl;
            continue;
        }
        unordered_map<ll, int>values;
        for (int j = 0 ; j < n; j++) {
            ll e;
            cin>>e;
            if (values.find(e) == values.end()) values[e] = 0;
            values[e]+=1;
        }
        vector<pair<ll, int> > vals;
        for (auto it: values) vals.push_back(it);
        sort(vals.begin(), vals.end(), comp);
        int i = 0;
        while (i < vals.size()-1) {
            k-=vals[i].second;
            if (k < 0) break;
            i+=1;
        }
        cout<<vals.size()-i<<endl;

    }
    return 0;
}


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

using namespace std;

#define ll long long int

bool comp (pair<ll, int> a, pair<ll, int> b) {
    return a.second < b.second;
}

int main(){
    int t;
    cin>>t;
    for (int ii = 0;ii<t;ii++) {
        int n,k;
        cin>>n>>k;
        if (k >= n-1){
            for (int j = 0 ; j < n; j++) {
                ll e;
                cin>>e;
            }
            cout <<"1"<<endl;
            continue;
        }
        vector<ll>values;
        //unordered_map<ll, int>values;
        for (int j = 0 ; j < n; j++) {
            ll e;
            cin>>e;
            values.push_back(e);
            //if (values.find(e) == values.end()) values[e] = 0;
            //values[e]+=1;
        }
        sort(values.begin(), values.end());
        vector<pair<ll, int> > vals;
        int c = 1;
        ll p = values[0];
        for (int i = 1;i < values.size();i++) {
            if (p == values[i]){
                c+=1;
            }
            else{
                pair<ll,int> pp;
                pp.first = p;
                pp.second = c;
                vals.push_back(pp);
                c = 1;
                p = values[i];
            }
        }
        pair<ll,int> pp;
        pp.first = p;
        pp.second = c;
        vals.push_back(pp);
        sort(vals.begin(), vals.end(), comp);
        int i = 0;
        while (i < vals.size()-1) {
            k-=vals[i].second;
            if (k < 0) break;
            i+=1;
        }
        cout<<vals.size()-i<<endl;

    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long int

bool comp (pair<ll, int> a, pair<ll, int> b) {
    return a.second < b.second;
}

int main(){
    int t;
    cin>>t;
    for (int ii = 0;ii<t;ii++) {
        int n,k;
        cin>>n>>k;
        unordered_map<ll, int>values;
        for (int j = 0 ; j < n; j++) {
            ll e;
            cin>>e;
            if (values.find(e) == values.end()) values[e] = 0;
            values[e]+=1;
        }
        vector<pair<ll, int> > vals;
        for (auto it: values) vals.push_back(it);
        sort(vals.begin(), vals.end(), comp);
        int i = 0;
        while (i < vals.size()-1) {
            k-=vals[i].second;
            if (k < 0) break;
            i+=1;
        }
        cout<<vals.size()-i<<endl;

    }
    return 0;
}


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

using namespace std;

#define ll long long int

bool comp (pair<ll, int> a, pair<ll, int> b) {
    return a.second < b.second;
}

int main(){
    int t;
    cin>>t;
    for (int ii = 0;ii<t;ii++) {
        int n,k;
        cin>>n>>k;
        if (k >= n-1){
            for (int j = 0 ; j < n; j++) {
                ll e;
                cin>>e;
            }
            cout <<"1"<<endl;
            continue;
        }
        unordered_map<ll, int>values;
        for (int j = 0 ; j < n; j++) {
            ll e;
            cin>>e;
            if (values.find(e) == values.end()) values[e] = 0;
            values[e]+=1;
        }
        vector<pair<ll, int> > vals;
        for (auto it: values) vals.push_back(it);
        sort(vals.begin(), vals.end(), comp);
        int i = 0;
        while (i < vals.size()-1) {
            k-=vals[i].second;
            if (k < 0) break;
            i+=1;
        }
        cout<<vals.size()-i<<endl;

    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

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

void solve() {
    std::string a, b, c;
    std::cin >> a >> b >> c;
    
    const int n = a.size(), m = b.size(), l = c.size();
    std::priority_queue<std::array<int, 3>, std::vector<std::array<int, 3>>, std::greater<>> q;
    q.push({0, 0, 0});
    int ans = 1e9;

    std::vector<bool> vis(n);
    while (!q.empty()) {
        const auto [x, i, j] = q.top();
        q.pop();

        const int idx = i + j;
        if (vis[idx]) {
            continue;
        }

        if (idx == l) {
            ans = std::min(ans, x);
            continue;
        }

        if (i < n) {
            q.push({x + (c[idx] != a[i]), i + 1, j});
        }
        if (j < m) {
            q.push({x + (c[idx] != b[j]), i, j + 1});
        }
    }
    
    std::cout << ans << '\n';
}

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

    int t;
    std::cin >> t;

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

    return 0;
}

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

void solve() {
    std::string a, b, c;
    std::cin >> a >> b >> c;
    
    const int n = a.size(), m = b.size(), l = c.size();
    std::priority_queue<std::array<int, 3>, std::vector<std::array<int, 3>>, std::greater<>> q;
    q.push({0, 0, 0});
    int ans = 1e9;

    std::set<std::pair<int, int>> s;
    while (!q.empty()) {
        const auto [x, i, j] = q.top();
        q.pop();

        if (s.count({i, j})) {
            continue;
        }
        s.insert({i, j});

        const int idx = i + j;
        if (idx == l) {
            ans = std::min(ans, x);
            continue;
        }

        if (i < n) {
            q.push({x + (c[idx] != a[i]), i + 1, j});
        }
        if (j < m) {
            q.push({x + (c[idx] != b[j]), i, j + 1});
        }
    }
    
    std::cout << ans << '\n';
}

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

    int t;
    std::cin >> t;

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

    return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


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

void solve() {
    std::string a, b, c;
    std::cin >> a >> b >> c;
    
    const int n = a.size(), m = b.size(), l = c.size();
    std::queue<std::array<int, 3>> q;
    q.push({0, 0, 0});
    int ans = 1e9;

    while (!q.empty()) {
        const auto [x, i, j] = q.front();
        q.pop();

        const int idx = i + j;
        if (idx == l) {
            ans = std::min(ans, x);
            continue;
        }

        if (i < n && c[idx] == a[i]) {
            q.push({x, i + 1, j});
        }
        if (j < m && c[idx] == b[j]) {
            q.push({x, i, j + 1});
        }
        q.push({x + 1, i + 1, j});
        q.push({x + 1, i, j + 1});
    }
    
    std::cout << ans << '\n';
}

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

    int t;
    std::cin >> t;

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

    return 0;
}