ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    unordered_map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            k-=counts[e1];
            res--;
            e1++;
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}

Submission (verdict: Accepted):
/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            k-=counts[e1];
            res--;
            e1++;
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    unordered_map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            res--;
            e1++;
            k-=counts[e1];
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}

Submission (verdict: Time limit exceeded on test 11):
/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    unordered_map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            k-=counts[e1];
            res--;
            e1++;
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    unordered_map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            res--;
            e1++;
            k-=counts[e1];
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define int long long
void solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>>a,b;
    int sm1=0,sm2=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.push(x);
        sm1+=x;
    }
    for(int i=1;i<=m;i++){
        cin>>x;
        b.push(x);
        sm2+=x;
    }
    if(sm1!=sm2){
        cout<<"No"<<endl;
        return ;
    }
    else {
        while(!a.empty()){
            int x=a.top(),y=b.top();
            if(x==y){
                a.pop();
                b.pop();
                continue;
            }
            else {
                a.pop();
                int xx=a.top();
                if(xx-x>1){
                    cout<<"No"<<endl;
                    return ;
                }
                a.pop();
                a.push(x+xx);
            }
        }
    }
    if(a.empty()&&b.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define int long long
void solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>>a,b;
    int sm1=0,sm2=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.push(x);
        sm1+=x;
    }
    for(int i=1;i<=m;i++){
        cin>>x;
        b.push(x);
        sm2+=x;
    }
    if(sm1!=sm2){
        cout<<"No"<<endl;
        return ;
    }
    else {
        while(!a.empty()){
            int x=a.top(),y=b.top();
            if(x>y)break;
            if(x==y){
                a.pop();
                b.pop();
                continue;
            }
            else {
                a.pop();
                int xx=a.top();
                if(xx-x>1){
                    cout<<"No"<<endl;
                    return ;
                }
                a.pop();
                a.push(x+xx);
            }

        }
    }
    if(a.empty()&&b.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define int long long
void solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>>a,b;
    int sm1=0,sm2=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.push(x);
        sm1+=x;
    }
    for(int i=1;i<=m;i++){
        cin>>x;
        b.push(x);
        sm2+=x;
    }
    if(sm1!=sm2){
        cout<<"No"<<endl;
        return ;
    }
    else {
        while(!a.empty()){
            int x=a.top(),y=b.top();
            if(x>y)break;
            if(x==y){
                a.pop();
                b.pop();
                continue;
            }
            else {
                a.pop();
                int xx=a.top();
                if(xx-x>1){
                    cout<<"No"<<endl;
                    return ;
                }
                a.pop();
                a.push(x+xx);
            }

        }
    }
    if(a.empty()&&b.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define int long long
void solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int>a,b;
    int sm1=0,sm2=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.push(x);
        sm1+=x;
    }
    for(int i=1;i<=m;i++){
        cin>>x;
        b.push(x);
        sm2+=x;
    }
    if(sm1!=sm2){
        cout<<"No"<<endl;
        return ;
    }
    else {
        while(!a.empty()){
            int x=a.top(),y=b.top();
            b.pop();
            if(x>y){
                cout<<"No"<<endl;
                return ;
            }
            if(x==y)a.pop();
            else {
                b.push(y/2);
                b.push((y+1)/2);
            }
        }
    }
    if(a.empty()&&b.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define int long long
void solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>>a,b;
    int sm1=0,sm2=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.push(x);
        sm1+=x;
    }
    for(int i=1;i<=m;i++){
        cin>>x;
        b.push(x);
        sm2+=x;
    }
    if(sm1!=sm2){
        cout<<"No"<<endl;
        return ;
    }
    else {
        while(!a.empty()){
            int x=a.top(),y=b.top();
            if(x==y){
                a.pop();
                b.pop();
                continue;
            }
            else {
                a.pop();
                int xx=a.top();
                if(xx-x>1){
                    cout<<"No"<<endl;
                    return ;
                }
                a.pop();
                a.push(x+xx);
            }
        }
    }
    if(a.empty()&&b.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define ll  long long
#define pp push_back
#define ones(x) __builtin_popcountll(x)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
// 32bit(1)=2147483647
// 2d vector:vector<vector<ll>> vec1( parentsz , vector<ll> (sz));
using namespace std;
char di[]={'D','L','U','R'};
int  dx[]={1,0,-1,0,-1,1,-1,1};
int  dy[]={0,-1,0,1,-1,-1,1,1};
const int N = 2e3 + 5, M = 1e5+5, LOG = 20, inf = 0x3f3f3f3f;
ll MOD = 1e9 + 7;
ll infLL = 0x3f3f3f3f3f3f3f3f;

bool const sorted (const pair<ll,ll> &p1,const pair <ll,ll> &p2){
    if(p1.first==p2.first) return p1.second<p2.second;
    return p1.first<p2.first;
}

int fastpower(ll x, ll y,ll p)
{
    ll res = 1;
    while (y > 0) {
        if (y % 2 == 1)
            res = (res * x)%MOD;
        y = y >> 1LL;
        x = (x * x) % MOD;
    }
    return res;
}

vector<ll>divisors(ll n){
    vector<ll>arr;
    arr.pp(0);
    for (long long i = 1; i*i <=n ; ++i) {
        if(n%i==0){
            arr.pp(i);
            if(i*i!=n){
                arr.pp(n/i);
            }
        }
    }
    return arr;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

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

ll add(ll a, ll b){
    return (a%MOD + b%MOD)%MOD;
}
ll subtract(ll a, ll b){
    return (a%MOD - b%MOD + 2*MOD)%MOD;
}
int lcm(int a, int b) {
    return (a / gcd(a, b)) * b;
}

void solve(){
   ll n;cin>>n;
   vector<ll>v(n);
    for (long long i = 0; i < n; ++i) {
        cin>>v[i];
    }
    bool f=1;
    ll tmp;

    for (long long i = 0; i < n; ++i) {
        tmp= min(v[i],v[i+1]);
        v[i]-=tmp;v[i+1]-=tmp;
        if(v[i+1]>v[i])
            f=0;
            break;

    }
    if(!f) yes
    else no



}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    ll t;
    t = 1;
    cin>>t;
    while(t--){
        solve();
    }

}
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
# cook your dish here

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n):
        a[i] -= a[i - 1]
            
    
    if a == sorted(a):
        print("Yes")
    else:
        print("NO")

Submission (verdict: Accepted):
# cook your dish here

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n):
        mn = min(a[i - 1], a[i])
        a[i - 1] -= mn
        a[i] -= mn
            
    
    if a == sorted(a):
        print("Yes")
    else:
        print("NO")
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
# cook your dish here

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n):
        if a[i - 1] < a[i]:
            a[i] -= a[i - 1]
            a[i - 1] = 0
            
    
    if a == sorted(a):
        print("Yes")
    else:
        print("NO")
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
# cook your dish here

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n):
        if a[i - 1] < a[i]:
            a[i] -= a[i - 1]
            a[i - 1] = 0
            
    
    if a == sorted(a):
        print("Yes")
    else:
        print("NO")

Submission (verdict: Wrong answer on test 1):
# cook your dish here

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n):
        a[i] -= a[i - 1]
            
    
    if a == sorted(a):
        print("Yes")
    else:
        print("NO")
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,int ind3,string a,string b,string c){
    if((ind>=(a.size()) && ind2>=(b.size())) || ind3==c.size()){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    int ans=INT_MAX;
    if(ind<n){
    if(a[ind]==c[ind3]){
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c));
    }else{
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c)+1);
    }
    }
    if(ind2<b.size()){
    if(b[ind2]==c[ind3]){
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c));
    }else{
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
int res = func(0,0,0,a,b,c);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,string &a,string &b,string &c){
    if(ind>=(a.size()) && ind2>=(b.size())){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    int ans=INT_MAX;
    if(ind<n){
    if(a[ind]==c[ind+ind2]){
        ans = min(ans,func(ind+1,ind2,a,b,c));
    }else{
        ans = min(ans,func(ind+1,ind2,a,b,c)+1);
    }
    }
    if(ind2<b.size()){
    if(b[ind2]==c[ind + ind2]){
        ans = min(ans,func(ind,ind2+1,a,b,c));
    }else{
        ans = min(ans,func(ind,ind2+1,a,b,c)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
int res = func(0,0,a,b,c);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,int ind3,string a,string b,string c,string r){
    if(ind>=(a.size()) && ind2>=(b.size())){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    // string r;
    int ans=INT_MAX;
    if(ind<n){
    r+= a[ind];
    if(r.back()==c[ind3]){
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c,r));
    }else{
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c,r)+1);
    }
    }
    if(ind2<b.size()){
    r+= b[ind2];
    if(r.back()==c[ind3]){
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c,r));
    }else{
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c,r)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
string r;
int res = func(0,0,0,a,b,c,r);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,int ind3,string a,string b,string c,string r){
    if(ind>=(a.size()) && ind2>=(b.size())){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    // string r;
    int ans=INT_MAX;
    if(ind<n){
    r+= a[ind];
    if(r.back()==c[ind3]){
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c,r));
    }else{
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c,r)+1);
    }
    }
    if(ind2<b.size()){
    r+= b[ind2];
    if(r.back()==c[ind3]){
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c,r));
    }else{
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c,r)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
string r;
int res = func(0,0,0,a,b,c,r);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}

Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,int ind3,string a,string b,string c){
    if((ind>=(a.size()) && ind2>=(b.size())) || ind3==c.size()){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    int ans=INT_MAX;
    if(ind<n){
    if(a[ind]==c[ind3]){
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c));
    }else{
        ans = min(ans,func(ind+1,ind2,ind3+1,a,b,c)+1);
    }
    }
    if(ind2<b.size()){
    if(b[ind2]==c[ind3]){
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c));
    }else{
        ans = min(ans,func(ind,ind2+1,ind3+1,a,b,c)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
int res = func(0,0,0,a,b,c);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}