ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int

int main() {
    IOS
    ll t;
    cin >> t;
    while (t--) {
        ll n, m;
        cin >> n >> m;

        vector<ll> a(n), b(m);
        multiset<ll> myset;

        ll suma = 0, sumb = 0;
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            suma += a[i];
            myset.insert(a[i]);
        }

        for (ll i = 0; i < m; i++) {
            cin >> b[i];
            sumb += b[i];
        }

        if (suma != sumb) {
            cout << "NO" << nl;
            continue;
        }


        multiset<ll> splitSet(b.begin(), b.end());

        bool possible = true;
        while (!splitSet.empty()) {
            ll largest = *splitSet.rbegin();
            splitSet.erase(prev(splitSet.end()));

            auto it = myset.find(largest);
            if (it != myset.end()) {
                myset.erase(it);
            } else {

                if (largest == 1) {
                    possible = false;
                    break;
                }


                splitSet.insert(largest / 2);
                splitSet.insert((largest + 1) / 2);
            }
        }

        if (possible && myset.empty()) {
            cout << "YES" << nl;
        } else {
            cout << "NO" << nl;
        }
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
ll mod = 1e+7;

int main(){
    IOS
    ll t;
    cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        priority_queue<ll> a,b;

        for(ll i=0; i<n; i++){
            ll temp;
            cin>>temp;
            a.push(temp);
        }
        for(ll i=0; i<m; i++){
            ll temp;
            cin>>temp;
            b.push(temp);
        }
        bool broke= false;
        while(!a.empty()){
            if(b.size()>a.size() || b.empty()){
                cout<<"NO"<<'\n';
                broke = true;
                break;
            }

            ll num=b.top();
            b.pop();
            if(num<a.top()){
                cout<<"NO"<<'\n';
                broke = true;
                break;
            }
            if(num==a.top()){
                a.pop();
            }else{
                b.push(num/2);
                b.push((num+1)/2);
            }
        }
        if(!broke){
            if(!b.empty()){
                cout<<"NO"<<'\n';
            }else{
                cout<<"YES"<<'\n';
            }
        }

    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
/*_______________________*****________________________*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
/*_______________________MACRO DEFINITIONS ________________________*/
#define endl "\n"
#define int long long  
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
 
//some useful functions and identifiers as macro
#define ff first
#define ss second
#define pb push_back
#define set_bits __builtin_popcountll
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define pinf 1e18
#define ninf -1e18
#define MOD 1000000007
#define PI 3.141592653589793238462
#define loop(s, e) for(int i = s; i < e; i++)
#define rloop(e, s) for(int i = e; i>= s; i--)
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};
 
/*______________________ COMMON FUNCTION DEFINITIONS _________________________*/
 
int gcd(int x , int y){return y == 0 ? x : gcd(y,x%y) ;}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
//XXX Don't use ceil XXX
int ceil2(int a, int b) {
    return (a + b - 1) / b;
}

int mpow(int base, int exp) { //binary exponentiation (modular power) (change MOD if required)
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}
 
int mdivide (int a, int b) {  //valid when MOD is prime
  return ((ll) (a%MOD) * mpow(b,MOD-2)) % MOD;
}

/*_________________________________ DEBUGGER ________________________________*/
#define printvec(arr) for(int i = 0; i < arr.size(); i++){cout<<arr[i]<<" ";}cout<<endl;
#define dbg(x) cout<<"value of "<<#x<<" "<<x<<endl;
 
       
#define MULTI_TESTS

void solve(int testIdx){

  string s;
  cin>>s;
  
  for(int i=0; i<s.size(); i++){
      int x = s[i]-'0';
      int id = i;
      if(x == 0) continue;
      for(int j=i+1; j<min((ll)s.size(), ll(i+10)); j++){
          int y = s[j]-'0';
          if(y-(j-i) > x){
              id = j;
              x = y-(j-i);
          }
      }
      swap(s[i], s[id]);
      s[i] = x+'0';
  }
  cout<<s<<endl;
  
  
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
  freopen("inputf.in", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  int numTests = 1;
  #ifdef MULTI_TESTS
    cin >> numTests;
  #endif
  for (int testIdx = 1; testIdx <= numTests; testIdx++) {
    solve(testIdx);
  }
  
  return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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


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

	unsigned t;
	std::cin >> t;
	std::map<int, int> al;
	std::vector<std::vector<int>> oreiller;
	while (t --> 0) {
		unsigned n;
		std::cin >> n;

		oreiller.resize(n + 1);
		for (unsigned i = 0; i < n - 1; ++i) {
			unsigned u, v;
			std::cin >> u >> v;
			++al[u];
			++al[v];
			oreiller[u].push_back(v);
			oreiller[v].push_back(u);
		}

		using pair_type = decltype(al)::value_type;
		auto pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		unsigned counter = pr->second;

		int the = pr->first;
		for (int a : oreiller[the]) {
			oreiller[a].erase(std::find(oreiller[a].begin(), oreiller[a].end(), the));
			--al[a];
		}

		al.erase(pr);

		
		pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		counter += pr->second - 1;

		std::cout << counter << '\n';

		oreiller.clear();
		al.clear();
	}
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>


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

	unsigned t;
	std::cin >> t;
	std::map<int, int> al;
	std::vector<std::vector<int>> oreiller;
	while (t --> 0) {
		unsigned n;
		std::cin >> n;

		oreiller.resize(n + 1);
		for (unsigned i = 0; i < n - 1; ++i) {
			unsigned u, v;
			std::cin >> u >> v;
			++al[u];
			++al[v];
			oreiller[u].push_back(v);
			oreiller[v].push_back(u);
		}

		using pair_type = decltype(al)::value_type;
		auto pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		unsigned counter = pr->second;

		int the = pr->first;
		for (int a : oreiller[the]) {
			oreiller[a].erase(std::find(oreiller[a].begin(), oreiller[a].end(), the));
			--al[a];
		}

		al.erase(pr);

		
		pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		counter += pr->second - 1;

		std::cout << counter << '\n';

		oreiller.clear();
		al.clear();
	}
}


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


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

	unsigned t;
	std::cin >> t;
	std::map<int, int> al;
	std::vector<std::vector<int>> oreiller;
	while (t --> 0) {
		unsigned n;
		std::cin >> n;

		oreiller.resize(n + 1);
		for (unsigned i = 0; i < n - 1; ++i) {
			unsigned u, v;
			std::cin >> u >> v;
			++al[u];
			++al[v];
			oreiller[u].push_back(v);
			oreiller[v].push_back(u);
		}

		using pair_type = decltype(al)::value_type;
		auto pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		unsigned counter = pr->second;

		int the = pr->first;
		for (int a : oreiller[the]) {
			oreiller[a].erase(std::find(oreiller[a].begin(), oreiller[a].end(), the));
			--al[a];
		}

		al.erase(pr);


		pr = std::max_element(
			std::begin(al), std::end(al),
			[] (const pair_type & p1, const pair_type & p2) {
				return p1.second < p2.second;
			}
		);
		counter += pr->second != 1 ?(pr->second - 1) : 1;

		std::cout << counter << '\n';

		oreiller.clear();
		al.clear();
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int final[n];
    for(int i=0;i<n;i++){cin>>final[i];}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=n-i;
    }
    int something=0;
    vector<int>first;
    vector<int>second;
    for(int i=0;i<n;i++)
        {
            int it=0;
            for(int j=0;j<n;j++)
            {
                if(final[i]==arr[j])
                {
                    it=j; break;
                }
            }
            something=something+it-i;
            for(int k=1;k<=it-i;k++)
            {
                first.push_back(arr[it]);
                second.push_back(arr[it-k]);
                swap(arr[it],arr[it-k]);
            }
        }
    int ans=(n*(n-1))/2 + something;
    cout<<ans<<endl;
    
        for(int i=n;i>1;i--)
        {
            for(int j=i-1;j>=1;j--)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=0;i<something;i++)
        {
            cout<<first[i]<<" "<<second[i]<<endl;
        }
    

    return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int final[n];
    for(int i=0;i<n;i++){cin>>final[i];}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=n-i;
    }
    int something=0;
    vector<int>first;
    vector<int>second;
    for(int i=0;i<n;i++)
        {
            int it=0;
            for(int j=0;j<n;j++)
            {
                if(final[i]==arr[j])
                {
                    it=j; break;
                }
            }
            something=something+it-i;
            for(int k=1;k<=it-i;k++)
            {
                first.push_back(arr[it]);
                second.push_back(arr[it-1]);
                swap(arr[it],arr[it-1]);
                it--;
            }
        }
    int ans=(n*(n-1))/2 + something;
    cout<<ans<<endl;
    
        for(int i=n;i>1;i--)
        {
            for(int j=i-1;j>=1;j--)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=0;i<something;i++)
        {
            cout<<first[i]<<" "<<second[i]<<endl;
        }
    

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int final[n];
    for(int i=0;i<n;i++){cin>>final[i];}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=n-i;
    }
    int something=0;
    vector<int>first;
    vector<int>second;
    for(int i=0;i<n;i++)
        {
            int it=0;
            for(int j=0;j<n;j++)
            {
                if(final[i]==arr[j])
                {
                    it=j; break;
                }
            }
            something=something+it-i;
            for(int k=1;k<=it-i;k++)
            {
                first.push_back(arr[it]);
                second.push_back(arr[it-k]);
                swap(arr[it],arr[it-k]);
            }
        }
    int ans=(n*(n-1))/2 + something;
    cout<<ans<<endl;
    
        for(int i=n;i>1;i--)
        {
            for(int j=i-1;j>=1;j--)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=0;i<something;i++)
        {
            cout<<first[i]<<" "<<second[i]<<endl;
        }
    

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int final[n];
    for(int i=0;i<n;i++){cin>>final[i];}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=n-i;
    }
    int something=0;
    vector<int>first;
    vector<int>second;
    for(int i=0;i<n;i++)
        {
            int it=0;
            for(int j=0;j<n;j++)
            {
                if(final[i]==arr[j])
                {
                    it=j; break;
                }
            }
            something=something+it-i;
            for(int k=1;k<=it-i;k++)
            {
                first.push_back(arr[it]);
                second.push_back(arr[it-1]);
                swap(arr[it],arr[it-1]);
                it--;
            }
        }
    int ans=(n*(n-1))/2 + something;
    cout<<ans<<endl;
    
        for(int i=n;i>1;i--)
        {
            for(int j=i-1;j>=1;j--)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=0;i<something;i++)
        {
            cout<<first[i]<<" "<<second[i]<<endl;
        }
    

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int final[n];
    for(int i=0;i<n;i++){cin>>final[i];}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=n-i;
    }
    int something=0;
    vector<int>first;
    vector<int>second;
    for(int i=0;i<n;i++)
        {
            int it=0;
            for(int j=0;j<n;j++)
            {
                if(final[i]==arr[j])
                {
                    it=j; break;
                }
            }
            int cc=it;
            something=something+it-i;
            for(int k=1;k<=cc-i;k++)
            {
                first.push_back(arr[it]);
                second.push_back(arr[it-1]);
                int c=arr[it];
                arr[it]=arr[it-1];  arr[it-1]=c;
                // swap(arr[it],arr[it-1]);
                it--;
            }
        }
    int ans=(n*(n-1))/2 + something;
    cout<<ans<<endl;
    
        for(int i=n;i>1;i--)
        {
            for(int j=i-1;j>=1;j--)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=0;i<something;i++)
        {
            cout<<first[i]<<" "<<second[i]<<endl;
        }
    

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

string SubstractMin(int n, vector<int> &a)
{
    int j = n - 1;
    while (j >= 1 && a[j - 1] <= a[j])
    {
        j--;
    }
    if (j == n - 1)
    {
        return "No";
    }
    int i = 0;
    while (i < j - 1)
    {
        int sub = min(a[i], a[i + 1]);
        a[i] -= sub;
        a[i + 1] -= sub;
        if (a[i] > a[i + 1])
        {
            return "No";
        }

        i++;
    }
    return "Yes";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
        for (int i : a)
        {
            cout << i << " ";
        }
    }

    return 0;
}

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

string SubstractMin(int n, vector<int> &a)
{
    int j = n - 1;
    while (j >= 1 && a[j - 1] <= a[j])
    {
        j--;
    }
    if (j == n - 1)
    {
        return "No";
    }
    int i = 0;
    while (i < j - 1)
    {
        int sub = min(a[i], a[i + 1]);
        a[i] -= sub;
        a[i + 1] -= sub;
        if (a[i] > a[i + 1])
        {
            return "No";
        }

        i++;
    }
    return "Yes";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

string SubstractMin(int n, vector<int> &a)
{
    int j = n - 1;
    while (j >= 1 && a[j - 1] <= a[j])
    {
        j--;
    }
    if (j == n - 1)
    {
        return "No";
    }
    int i = 0;
    while (i < j - 1)
    {
        int sub = min(a[i], a[i + 1]);
        a[i] -= sub;
        a[i + 1] -= sub;
        if (a[i] > a[i + 1])
        {
            return "No";
        }

        i++;
    }
    return "Yes";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
    }

    return 0;
}

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

string SubstractMin(int n, vector<long long> &a)
{
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] > a[i]) j = i;
    }
    if (j == 0) { 
        return "YES";
    }
    for (int i = 0; i < j; i++) {
        long long minN = min(a[i], a[i+1]);
        a[i] -= minN;
        a[i+1] -= minN;
    }
    return (is_sorted(a.begin(), a.end()) ? "YES" : "NO");
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

string SubstractMin(int n, vector<int> &a)
{
    int j = n - 1;
    while (j >= 1 && a[j - 1] <= a[j])
    {
        j--;
    }
    if (j == n - 1)
    {
        return "No";
    }
    int i = 0;
    while (i < j - 1)
    {
        int sub = min(a[i], a[i + 1]);
        a[i] -= sub;
        a[i + 1] -= sub;
        if (a[i] > a[i + 1])
        {
            return "No";
        }

        i++;
    }
    return "Yes";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cout << SubstractMin(n, a) << endl;
        for (int i : a)
        {
            cout << i << " ";
        }
    }

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

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int dp(int i, int j, int n, string a, string b, string c) {
    if (i + j >= n) return 0;
    if (i == a.length()) return dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1);
    if (j == b.length()) return dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1);
    return min(dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1), dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1));
}

void solve() {
    int na, nb, nc;
    string a, b, c;
    cin >> a >> b >> c;
    na = a.length();
    nb = b.length();
    nc = c.length();
    // vector<vector<int>> dp(1001, vector<int>(1001, 0));
    // for (int i = na; i >= 0; i--) {
    //     for (int j = nb; j >= 0; j--) {
    //         if (i + j >= nc) continue;
    //         dp[i][j] = min(dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1), dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1));
    //     }
    // }
    // cout << dp[0][0] << "\n";
    cout << dp(0, 0, nc, a, b, c) << "\n";
}

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


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

int dp(int i, int j, int n, string a, string b, string c) {
    if (i + j >= n) return 0;
    if (i == a.length()) return dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1);
    if (j == b.length()) return dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1);
    return min(dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1), dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1));
}

void solve() {
    int na, nb, nc;
    string a, b, c;
    cin >> a >> b >> c;
    na = a.length();
    nb = b.length();
    nc = c.length();
    vector<vector<int>> dp(1001, vector<int>(1001, 0));
    for (int i = na; i >= 0; i--) {
        for (int j = nb; j >= 0; j--) {
            if (i + j >= nc) continue;
            if (i == na) dp[i][j] = dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1);
            else if (j == nb) dp[i][j] = dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1);
            else dp[i][j] = min(dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1), dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1));
        }
    }
    cout << dp[0][0] << "\n";
    // cout << dp(0, 0, nc, a, b, c) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


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

int dp(int i, int j, int n, string a, string b, string c) {
    if (i + j >= n) return 0;
    return min(dp(i + 1, j, n, a, b, c) + ((a[i] == c[i + j]) ? 0 : 1), dp(i, j + 1, n, a, b, c) + ((b[j] == c[i + j]) ? 0 : 1));
}

void solve() {
    int na, nb, nc;
    string a, b, c;
    cin >> a >> b >> c;
    na = a.length();
    nb = b.length();
    nc = c.length();
    // vector<vector<int>> dp(1001, vector<int>(1001, 0));
    // for (int i = na; i >= 0; i--) {
    //     for (int j = nb; j >= 0; j--) {
    //         if (i + j >= nc) continue;
    //         dp[i][j] = min(dp[i + 1][j] + ((a[i] == c[i + j]) ? 0 : 1), dp[i][j + 1] + ((b[j] == c[i + j]) ? 0 : 1));
    //     }
    // }
    // cout << dp[0][0] << "\n";
    cout << dp(0, 0, nc, a, b, c) << "\n";
}

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