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


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <map>
using namespace std;

bool isDivisibleBy9(long long int n) {
    map<int, long long int> m;
    long long int sum = 0;
    while (n > 0) {
        sum += n % 10;
        if (n % 10 == 2) {
            m[2]++;
        } else if (n % 10 == 3) {
            m[3]++;
        }
        n = n / 10;
    }
    if (sum % 9 == 0) return true;

   
    for (int i = 0; i <= m[2]; i++) {
        for (int j = 0; j <= m[3]; j++) {
            if ((sum - 2 * i - 3 * j + 4 * i + 9 * j) % 9 == 0) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long int n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    cin>>n>>l>>r;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<=n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    cin>>n>>l>>r;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<=n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}

Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    
    cin>>n>>l>>r;
    l=l-1;
    r=r-1;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
    //  for(int value:left){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  for(int value:right){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  cout<<sum_left <<" "<<sum_right<<endl;
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    
    cin>>n>>l>>r;
    l=l-1;
    r=r-1;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
    //  for(int value:left){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  for(int value:right){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  cout<<sum_left <<" "<<sum_right<<endl;
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
 cin>>t;
  while(t--){
    int n,l,r;
    
    cin>>n>>l>>r;
    l=l-1;
    r=r-1;
    vector<int> v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
     vector<int> left;
     vector<int> right;
     for(int i=0; i<=r;i++){
      left.push_back(v[i]);
     }
     for(int i=l; i<n;i++){
      right.push_back(v[i]);
     }
     int k=r-l+1;
     sort(left.begin(),left.end());
     sort(right.begin(),right.end());
     long long int sum_left=0, sum_right=0;
     for(int i=0;i<k;i++){
      sum_left=sum_left+left[i];
     }
     for(int i=0;i<k;i++){
      sum_right=sum_right+right[i];
     }
    //  for(int value:left){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  for(int value:right){
    //   cout<<value<<" ";
    //  }
    //  cout<<endl;
    //  cout<<sum_left <<" "<<sum_right<<endl;
     cout<<min(sum_left,sum_right)<<endl;
  }
return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

#define ll long long

int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> v,z;
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[i],c[j]});
                z.push_back({c[j],c[i]});
            }
        }
    }
    
    reverse(z.begin(),z.end());
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
    }
    
    cout<<count<<endl;
    
    for(int i=0;i<z.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    for(int i=0;i<z.size();i++){
        cout<<z[i].first<<" "<<z[i].second<<endl;
    }
    
    for(int i=z.size();i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    return 0;
}

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

#define ll long long

int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> v,z;
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[i],c[j]});
                z.push_back({c[j],c[i]});
            }
        }
    }
    
    reverse(z.begin(),z.end());
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
    }
    
    cout<<count<<endl;
    
    for(int i=0;i<z.size();i++){
        cout<<z[i].first<<" "<<z[i].second<<endl;
    }
    
    for(int i=0;i<z.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    for(int i=z.size();i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

#define ll long long

int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> v,z;
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[i],c[j]});
                z.push_back({c[j],c[i]});
            }
        }
    }
    
    reverse(z.begin(),z.end());
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
    }
    
    cout<<count<<endl;
    
    for(int i=0;i<z.size();i++){
        cout<<z[i].first<<" "<<z[i].second<<endl;
    }
    
    for(int i=0;i<z.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    for(int i=z.size();i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> ans;
    
    for(int i=0;i<n;i++){
        vector<pair<int,int>> v,z;
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[j],c[i]});
                z.push_back({c[i],c[j]});
            }
        }
        sort(v.begin(),v.end());
        sort(z.begin(),z.end());
        reverse(z.begin(),z.end());
        for(int k=0;k<v.size();k++){
            ans.push_back(v[k]);
        }
        for(int k=0;k<v.size();k++){
            ans.push_back(z[k]);
        }
        
        v={};
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(int k=0;k<v.size();k++){
            ans.push_back(v[k]);
        }
        
    }
    
    
    
    // for(int i=0;i<n;i++){
    //     for(int j=i+1;j<n;j++){
    //         if(c[i]>c[j]){
    //             count++;
    //             v.push_back({c[i],c[j]});
    //         }
    //     }
    // }
    
    cout<<count<<endl;
    
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    
    
    
    
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

#define ll long long

int main(){
    int n;
    cin>>n;
    
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    
    ll count=0;
    
    vector<pair<int,int>> v,z;
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]<c[j]){
                count+=2;
                v.push_back({c[i],c[j]});
                z.push_back({c[j],c[i]});
            }
        }
    }
    
    reverse(z.begin(),z.end());
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[i]>c[j]){
                count++;
                v.push_back({c[i],c[j]});
            }
        }
    }
    
    cout<<count<<endl;
    
    for(int i=0;i<z.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    for(int i=0;i<z.size();i++){
        cout<<z[i].first<<" "<<z[i].second<<endl;
    }
    
    for(int i=z.size();i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    
    
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "DEBUG/debug.h"
#else
#define debug(x)
#endif
using namespace std;
bool Delete(long long ele, multiset<long long> &a)
{
    auto it = a.find(ele);
    if (it != a.end())
    {
        a.erase(it);
        return true;
    }
    if (ele <= 1)
    {
        return false;
    }
    long long x = ele / 2;
    long long y = (ele + 1) / 2;
    return Delete(x, a) & Delete(y, a);
}
void solve()
{
    long long n, m;
    cin >> n >> m;
    vector<long long> va(n), vb(m);
    for (auto &x : va)
        cin >> x;
    for (auto &y : vb)
        cin >> y;
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    multiset<long long> a;
    for (auto &e : va)
    {
        a.insert(e);
    }
    debug(a);
    debug(va);
    debug(vb);
    for (long long i = 0; i < m; i++)
    {
        long long ele = vb[i];
        if (!Delete(ele, a))
        {
            cout << "No" << endl;
            return;
        }
    }
    if(!a.empty())
    {
        cout<<"No\n";
        return;
    }
    cout << "Yes\n";
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

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

    long long t = 1;
    cin >> t;

    while (t--)
    {
        // cout<<9-t+1<<" ";
        solve();
    }

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


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

// Aliases
using ll = long long;
using ull = unsigned long long;
using ld = long double;

// Constants
constexpr ll INF = 4e18;
constexpr ld EPS = 1e-9;
constexpr ll MOD = 998244353;

// Macros
#define F first
#define S second
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define pb push_back
#define MP make_pair
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)

// Modular arithmetic functions
ll inv(ll i) {
    if (i == 1) return 1;
    return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}

ll mod_mul(ll a, ll b) {
    return (a % MOD * b % MOD) % MOD;
}

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

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

ll pwr(ll a, ll b) {
    ll res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

// Fast I/O
istream& operator>>(istream &is, vector<ll> &v) {
    for (auto &x : v) is >> x;
    return is;
}

ostream& operator<<(ostream &os, const vector<ll> &v) {
    for (auto &x : v) os << x << " ";
    return os;
}

// Main logic
void solve() {
    int n;
    cin>>n;

    vector<ll> a;
    for (int i = 0; i < n; i++) {
        int t;cin>>t;
        a.push_back(t);
    }
    rep(i,0,n-1){
        int mini=min(a[i],a[i+1]);
        a[i]-=mini;
        a[i+1]-=mini;
    }
    rep(i,0,n){
        if(a[i]>0){
            cout<<"no"<<endl;
            return;
        }
    }
    cout<<"yes"<<endl;
    return;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin >> T;

    auto start = high_resolution_clock::now();
    while (T--) {
        solve();
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr << "Time: " << duration.count() / 1000 << " ms" << endl;

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


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

#include <chrono>

using namespace std;

using namespace chrono;



// Aliases

using ll = long long;

using ull = unsigned long long;

using ld = long double;



// Constants

constexpr ll INF = 4e18;

constexpr ld EPS = 1e-9;

constexpr ll MOD = 998244353;



// Macros

#define F first

#define S second

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

#define allr(x) rbegin(x), rend(x)

#define pb push_back

#define MP make_pair

#define endl '\n'

#define rep(i, a, b) for (int i = a; i < b; i++)



// Modular arithmetic functions

ll inv(ll i) {

    if (i == 1) return 1;

    return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;

}



ll mod_mul(ll a, ll b) {

    return (a % MOD * b % MOD) % MOD;

}



ll mod_add(ll a, ll b) {

    return (a % MOD + b % MOD) % MOD;

}



ll mod_sub(ll a, ll b) {

    return (a % MOD - b % MOD + MOD) % MOD;

}



ll pwr(ll a, ll b) {

    ll res = 1;

    a %= MOD;

    while (b > 0) {

        if (b & 1) res = res * a % MOD;

        a = a * a % MOD;

        b >>= 1;

    }

    return res;

}



// Fast I/O

istream& operator>>(istream &is, vector<ll> &v) {

    for (auto &x : v) is >> x;

    return is;

}



ostream& operator<<(ostream &os, const vector<ll> &v) {

    for (auto &x : v) os << x << " ";

    return os;

}



// Main logic

void solve() {

    int n, l, r;

   cin >> n >> l >> r; // input n, l, r

   vector<long long> a(n);  // Create a vector of size n



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

       cin >> a[i]; // input the array elements

   }



   sort(a.begin(), a.end()); // sort the array



   // Calculate the sum of the smallest (r-l+1) elements

   long long res = 0;

   for(int i = l-1; i < r; i++) {

       res += a[i]; // Sum elements in the range [l, r]

   }



   cout << res << endl; // Output the result

   return;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int T;

    cin >> T;



    auto start = high_resolution_clock::now();

    while (T--) {

        solve();

    }

    auto stop = high_resolution_clock::now();

    auto duration = duration_cast<microseconds>(stop - start);

    cerr << "Time: " << duration.count() / 1000 << " ms" << endl;



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    a=bin(l)[2::]
    b=bin(r)[2::]
    i=32
    c=0
    while True:
        if(((1<<i)&r)!=0):
            c=max(c,i)
            if(((1<<i)&l)==0):
                break
        i-=1
    y=(1<<i)^((1<<(i+1))-1)
    mask = ~((1 << i) - 1)
    x = l & mask
    if((y+1)<=r and (y+1)!=x):
        print(y,x,y+1)
    elif((x+1)<=r and (x+1)!=x):
        print(y,x,x+1)
    elif(y!=l):
        print(l,y,x)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    a=bin(l)[2::]
    b=bin(r)[2::]
    i=32
    c=0
    while True:
        if(((1<<i)&r)!=0):
            c=max(c,i)
            if(((1<<i)&l)==0):
                break
        i-=1
    y=(1<<i)^((1<<(i+1))-1)
    x= ((1 << (c+1)) - 1) & ~((1 << i) - 1)
    if((y+1)<=r and (y+1)!=x):
        print(y,x,y+1)
    elif((x+1)<=r and (x+1)!=x):
        print(y,x,x+1)
    elif(y!=l):
        print(l,x,y)





    


Submission (verdict: Accepted):
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    a=bin(l)[2::]
    b=bin(r)[2::]
    i=32
    c=0
    while True:
        if(((1<<i)&r)!=0):
            c=max(c,i)
            if(((1<<i)&l)==0):
                break
        i-=1
    top_bits = l & ~((1 << i) - 1)
    x = top_bits | (1 << i)

    y = top_bits | ((1 << i) - 1)


    if(((y+1)<=r) and ((y+1)!=x) and ((y+1)>=l)):
        print(y,x,y+1)
    elif((x+1)<=r ):
        print(y,x,x+1)
    elif(y!=l):
        print(l,x,y)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    a=bin(l)[2::]
    b=bin(r)[2::]
    i=32
    c=0
    while True:
        if(((1<<i)&r)!=0):
            c=max(c,i)
            if(((1<<i)&l)==0):
                break
        i-=1
    y=(1<<i)^((1<<(i+1))-1)
    mask = ~((1 << i) - 1)
    x = l & mask
    if((y+1)<=r and (y+1)!=x):
        print(y,x,y+1)
    elif((x+1)<=r and (x+1)!=x):
        print(y,x,x+1)
    elif(y!=l):
        print(l,y,x)





    


Submission (verdict: Wrong answer on test 1):
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    a=bin(l)[2::]
    b=bin(r)[2::]
    i=32
    c=0
    while True:
        if(((1<<i)&r)!=0):
            c=max(c,i)
            if(((1<<i)&l)==0):
                break
        i-=1
    y=(1<<i)^((1<<(i+1))-1)
    x= ((1 << (c+1)) - 1) & ~((1 << i) - 1)
    if((y+1)<=r and (y+1)!=x):
        print(y,x,y+1)
    elif((x+1)<=r and (x+1)!=x):
        print(y,x,x+1)
    elif(y!=l):
        print(l,x,y)
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

int dp[1001][1001];
int valid[1001][1001];
int t;

int minChangedChars(string a, string b, string c)
{
  int i = a.size(), j = b.size();
  if (valid[i][j] == t)
    return dp[i][j];
  valid[i][j] = t;
  int acnt = 0, bcnt = 0;
  if (a.size() == 0)
  {
    for (int i = 0; i < c.size(); i++)
    {
      if (c[i] != b[i])
        bcnt++;
    }
    return dp[i][j] = bcnt;
  }

  if (b.size() == 0)
  {
    for (int i = 0; i < c.size(); i++)
    {
      if (c[i] != a[i])
        acnt++;
    }
    return dp[i][j] = acnt;
  }
  acnt = minChangedChars(a.substr(1), b, c.substr(1));
  if (a[0] != c[0])
    acnt++;
  bcnt = minChangedChars(a, b.substr(1), c.substr(1));
  if (b[0] != c[0])
    bcnt++;
  return dp[i][j] = min(acnt, bcnt);
}

int main()
{
  cin >> t;
  while (t)
  {
    string a, b, c;
    cin >> a >> b >> c;
    cout << minChangedChars(a, b, c) << endl;
    t--;
  }
  return 0;
}

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

// int dp[1001][1001];
// int valid[1001][1001];
// int t;

// int minChangedChars(string a, string b, string c)
// {
//   int i = a.size(), j = b.size();
//   if (valid[i][j] == t)
//     return dp[i][j];
//   valid[i][j] = t;
//   int acnt = 0, bcnt = 0;
//   if (a.size() == 0)
//   {
//     for (int i = 0; i < c.size(); i++)
//     {
//       if (c[i] != b[i])
//         bcnt++;
//     }
//     return dp[i][j] = bcnt;
//   }

//   if (b.size() == 0)
//   {
//     for (int i = 0; i < c.size(); i++)
//     {
//       if (c[i] != a[i])
//         acnt++;
//     }
//     return dp[i][j] = acnt;
//   }
//   acnt = minChangedChars(a.substr(1), b, c.substr(1));
//   if (a[0] != c[0])
//     acnt++;
//   bcnt = minChangedChars(a, b.substr(1), c.substr(1));
//   if (b[0] != c[0])
//     bcnt++;
//   return dp[i][j] = min(acnt, bcnt);
// }

// dp[i][j] = min(dp[i - 1][j] + a != c, dp[i][j - 1] + b != c)

int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    string a, b, c;
    cin >> a >> b >> c;
    vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, INT_MAX));
    dp[0][0] = 0;
    for (int i = 0; i <= a.size(); i++)
    {
      for (int j = 0; j <= b.size(); j++)
      {
        if (i > 0)
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[i + j - 1]));
        if (j > 0)
          dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
      }
    }
    cout << dp[a.size()][b.size()] << endl;
    // cout << minChangedChars(a, b, c) << endl;
  }
  return 0;
}