ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


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

using namespace std;

#define LL long long

#define PII pair<int, int>

#define PLL pair<LL, LL>

#define endl '\n'

const int N = 2e5 + 10;

void solve(){

    int n, x, y;

    cin >> n >> x >> y;

    vector<int> a(n + 1);

    if(x == (y + 1) % n || y == (x + 1) % n){

        if(n % 2){

            for(int i = 1;i <= n - 1;i++)a[i] = i % 2;

            a[n] = 2;

        }

        else {

            for(int i = 1;i <= n;i++)a[i] = i % 2;

        }

    }

    else{

        a[x] = 0, a[y] = 1;

        for(int i = x + 1;i <= y;i++){

            a[i] = (a[i - 1] + 1) % 2;

        }

        if(a[y] != 1)a[y] = 1, a[y - 1] = 2;

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

            a[i] = (a[i - 1] + 1) % 2;

        }

        a[0] = (a[n] + 1) % 2;

        for(int i = 1;i <= x;i++){

            a[i] = (a[i - 1] + 1) % 2;

        }

        if(a[x] != 0)a[x] = 0, a[x - 1] = 2;

    }

    for(int i = 1;i <= n;i++)cout << a[i] << ' ';

    cout << endl;

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int T = 1;

    cin >> T;

    while(T--){

        solve();

    }

}
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 7):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=[]
  while s:
    m=s[0]
    x=0
    for i in range(1,min(10,len(s))):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
      

Submission (verdict: Accepted):
for _ in range(int(input())):
  s=list(map(int,input()[::-1]))
  a=[]
  while s:
    m=s[-1]
    x=-1
    for i in range(-1,max(-11,-len(s)-1),-1):
      if x-m==9:
        break
      if s[i]+i+1>m:
        m=s[i]+i+1
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 7):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=""
  while s:
    m=s[0]
    x=0
    for i in range(1,min(10,len(s))):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a+=str(m)
    del s[x]
  print(a)
      

Submission (verdict: Time limit exceeded on test 7):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=[]
  while s:
    m=s[0]
    x=0
    for i in range(1,min(10,len(s))):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
Problem: 2050D - Digital string maximization
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 4):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=""
  while s:
    m=s[0]
    x=0
    for i in range(1,len(s)):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a+=str(m)
    del s[x]
  print(a)

Submission (verdict: Time limit exceeded on test 7):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=""
  while s:
    m=s[0]
    x=0
    for i in range(1,min(10,len(s))):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a+=str(m)
    del s[x]
  print(a)
Problem: 2050D - Digital string maximization
Language: Python 3


Submission (verdict: Time limit exceeded on test 4):
for _ in range(int(input())):
  s=list(map(int,input()))
  a=""
  while s:
    m=s[0]
    x=0
    for i in range(1,len(s)):
      if x+m==9:
        break
      if s[i]-i>m:
        m=s[i]-i
        x=i
    a+=str(m)
    del s[x]
  print(a)
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):

/*Don Paul*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define ld long double
#define el __int128
 
#define vl vector<ll>
#define ust unordered_set
#define ump unordered_map
#define prq priority_queue
 
#define pb push_back
#define pp pop_back
#define sz(x) ((int)x.size())
#define be(x) x.begin(), x.end()
#define farr(i, arr) for(int i=0; i<arr.size(); ++i)
#define fpr(it, m) for(auto it=m.begin(); it!=m.end(); ++it)


//Debugging tools

#define line cout<<"\n----------------------\n"
#define bline cout<<"\n======================\n"
#define parr(arr) for(int i=0; i<arr.size(); ++i) cout<<arr[i]<<" "; cout<<"\n";
#define pset(s) for(auto i=s.begin(); i!=s.end(); ++i) cout<<*i<<" "; cout<<"\n";
#define pmap(m) for(auto i=m.begin(); i!=m.end(); ++i) cout<<i->first<<" - "<<i->second<<"\n";
 
ll mod = 1e9 + 7;
ll inf = 7e18;
 
/*======================================================================================================================*/


ll find(vl &nums)
{
    ll i = 0;

    ll mx = -1e18;

    // parr(nums);

    while(sz(nums) != 1)
    {
        ll sum = 0;

        if(nums[0] < 0 && nums.back() < 0)
        {
            if(abs(nums.back()) > abs(nums[0]))
                reverse(be(nums));
        }

        else if(nums.back() < 0)
            reverse(be(nums));

        for(ll i=0; i<sz(nums)-1; ++i)
        {
            nums[i] = nums[i+1] - nums[i];
            // cout<<nums[i]<<" ";

            sum += nums[i];
        }

        nums.pop_back();

        // cout<<"\n";
        // cout<<sum<<"\n";

        mx = max(mx, sum);

        // line;
        ++i;
    }

    return nums[0];
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif

    int ti;
    cin>>ti;

    ll x;

    while(ti--)
    {
        ll n;
        cin>>n;

        vl nums;
        vl tnums;
        ll sum = 0;

        for(ll i=0; i<n; ++i)
        {
            cin>>x;

            sum += x;
            nums.pb(x);
        }

        tnums = nums;
        ll ans = find(nums);
        ans = max(ans, sum);

        cout<<ans<<"\n";


        // line;


    }


    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
#define nl '\n'
#define F first
#define S second
#define pai pair<int, int>


using namespace std;

int oz(int a, int b)
{
    return max(a - b, b - a);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> in(n, 0);
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> in[i];
        ans += in[i];
    }
    vector<int > vc = in;
    for (int i = 1; i <= n - 1; ++i)
    {
        vector<int> s = vc;
        ans = max({ans, -oz(vc[0], vc[vc.size() - 1]), oz(vc[0], vc[vc.size() - 1])});
        for (int j = 1; j < vc.size(); ++j)
            vc[j] -= s[j - 1];
        vc.erase(vc.begin());
    }
    cout << ans << nl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
  //  freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	while (t--)
        solve();
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
#define nl '\n'
#define F first
#define S second
#define pai pair<int, int>


using namespace std;

int oz(int a, int b)
{
    return max(a - b, b - a);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> in(n, 0);
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> in[i];
        ans += in[i];
    }
    vector<int > vc = in;
    for (int i = 1; i <= n - 1; ++i)
    {
        vector<int> s = vc;
        int sum = vc[vc.size() - 1] - vc[0];
        ans = max({ans, -sum, sum});
        for (int j = 1; j < vc.size(); ++j)
            vc[j] -= s[j - 1];
        vc.erase(vc.begin());
    }
    cout << ans << nl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
   // freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	while (t--)
        solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
#define nl '\n'
#define F first
#define S second
#define pai pair<int, int>


using namespace std;

int oz(int a, int b)
{
    return max(a - b, b - a);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> in(n, 0);
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> in[i];
        ans += in[i];
    }
    vector<int > vc = in;
    for (int i = 1; i <= n - 1; ++i)
    {
        vector<int> s = vc;
        ans = max({ans, -oz(vc[0], vc[vc.size() - 1]), oz(vc[0], vc[vc.size() - 1])});
        for (int j = 1; j < vc.size(); ++j)
            vc[j] -= s[j - 1];
        vc.erase(vc.begin());
    }
    cout << ans << nl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
  //  freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	while (t--)
        solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
#define nl '\n'
#define F first
#define S second
#define pai pair<int, int>


using namespace std;

int oz(int a, int b)
{
    return max(a - b, b - a);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> in(n, 0);
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> in[i];
        ans += in[i];
    }
    vector<int > vc = in;
    for (int i = 1; i <= n - 1; ++i)
    {
        vector<int> s = vc;
        int sum = vc[vc.size() - 1] - vc[0];
        ans = max({ans, -sum, sum});
        for (int j = 1; j < vc.size(); ++j)
            vc[j] -= s[j - 1];
        vc.erase(vc.begin());
    }
    cout << ans << nl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
   // freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	while (t--)
        solve();
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll int64_t
#define nl '\n'
#define F first
#define S second
#define pai pair<int, int>
#define int int64_t

using namespace std;

int oz(int a, int b)
{
    return max(a - b, b - a);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> in(n, 0);
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> in[i];
        ans += in[i];
    }
    vector<int > vc = in;
    for (int i = 1; i <= n - 1; ++i)
    {
        vector<int> s = vc;
        int sum = vc[vc.size() - 1] - vc[0];
        ans = max({ans, -sum, sum});
        for (int j = 1; j < vc.size(); ++j)
            vc[j] -= s[j - 1];
        vc.erase(vc.begin());
    }
    cout << ans << nl;
}

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	while (t--)
        solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

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

const int N=2e5+50;
int a[N],b[N];

signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> p2;
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum1+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            p2[b[j]]++;
            sum2+=b[j];
        }
        if(sum1!=sum2){
            cout<<"No"<<endl;
            continue;
        }
        vector<int> v;
        sort(a,a+n);
        for(int i=0;i<n;i++){
            if(p2[a[i]]>=1){
                p2[a[i]]--;
            }else{
                
                if(!v.empty()){
                    if(p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                    if(!v.empty()&&abs(v.back()-a[i])<=1){
                        int u=v.back();
                        v.pop_back();
                        v.push_back(a[i]+u);
                     //   cout<<v.back()<<endl;
                    }else{
                        v.push_back(a[i]);
                    }
                    if(!v.empty()&&p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                }else{
                    v.push_back(a[i]);
                }
            }
        }
        int flag=0;
        for(auto i:p2){
            if(i.second>0){
                flag=1;
                break;
            }
        }    
        if(!v.empty()||flag){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}
// 1中和相等
// 2 最大 小于 下面
// 3如果长度相等 判断 是否一样
// 4

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

bool solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int> a,b;
    for(int i=0;i<n;i++){
        cin>>x;
        a.push(x);
    }
    for(int j=0;j<m;j++){
        cin>>x;
        b.push(x);
    }
    int flag=0;
    while(a.size()&&b.size()){
        if(a.top()>b.top()||a.size()<b.size())return 0;
        if(a.top()==b.top()){a.pop();b.pop();continue;}
        int u=b.top();
        b.pop();
        b.push(u>>1);
        b.push(u+1>>1);
    }
    return a.empty()&&b.empty();
}
signed main(){
    int t;
    cin>>t;
    while(t--){
        cout<<(solve()?"Yes":"No")<<endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


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

const int N=2e5+50;
int a[N],b[N];

signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> p2;
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum1+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            p2[b[j]]++;
            sum2+=b[j];
        }
        if(sum1!=sum2){
            cout<<"No"<<endl;
            continue;
        }
        vector<int> v;
        sort(a,a+n);
        for(int i=0;i<n;i++){
            if(p2[a[i]]>=1){
                p2[a[i]]--;
            }else{
                
                if(!v.empty()){
                    if(p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                    if(!v.empty()&&abs(v.back()-a[i])<=1){
                        int u=v.back();
                        v.pop_back();
                        v.push_back(a[i]+u);
                     //   cout<<v.back()<<endl;
                    }
                    if(!v.empty()&&p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                }else{
                    v.push_back(a[i]);
                }
            }
        }
        int flag=0;
        for(auto i:p2){
            if(i.second>0){
                flag=1;
                break;
            }
        }    
        if(!v.empty()||flag){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}
// 1中和相等
// 2 最大 小于 下面
// 3如果长度相等 判断 是否一样
// 4
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 8):
#include <iostream>

#include <vector>

#include <algorithm>

#include <numeric>



using ll = long long;

using namespace std;



int main() {

    int t;



    cin >> t;

    

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

        int n, l, r;



        cin >> n;

        cin >> l;

        cin >> r;

        

        vector<ll> preSegment;

        vector<ll> segment;

        vector<ll> postSegment;

        

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

            ll v;

            cin >> v;

            

            if(i<l-1) {

                preSegment.push_back(v);

            } else if (i<r) {

                segment.push_back(v);

            } else {

                postSegment.push_back(v);

            }

            //preSegment.push_back(v);

            //segment.push_back(v);

            //postSegment.push_back(v);

        }



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

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

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





        ll sum = accumulate(segment.begin(), segment.end(), 0);



        ll Presum = sum;

        ll Postsum = sum;



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

            if(preSegment.at(i)<segment.at(r-l-i)) {

                Presum += preSegment.at(i);

                Presum -= segment.at(r-l-i);

            };

        }



        for(int i = 0; i < min(r-l+1, n-r); i++) {

            if(postSegment.at(i)<segment.at(r-l-i)) {

                Postsum += postSegment.at(i);

                Postsum -= segment.at(r-l-i);

            };

        }





        printf("%d\n", min(min(sum, Postsum), Presum));

        //printf("%d\n", sum);

        

    }



}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 16):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 1005, b1 = 1005, c1 = 1005,d1 = 1005;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < c.size() + 2; i++){
            for(int j = 0; j < c.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}

Submission (verdict: Wrong answer on test 17):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 1005, b1 = 1005, c1 = 1005,d1 = 1005;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < a.size() + 2; i++){
            for(int j = 0; j < b.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 16):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 1005, b1 = 1005, c1 = 1005,d1 = 1005;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < c.size() + 2; i++){
            for(int j = 0; j < c.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 17):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 1005, b1 = 1005, c1 = 1005,d1 = 1005;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < a.size() + 2; i++){
            for(int j = 0; j < b.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}

Submission (verdict: Accepted):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 5000, b1 = 5000, c1 = 5000,d1 = 5000;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < a.size() + 2; i++){
            for(int j = 0; j < b.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}