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

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

using namespace std;
typedef long long ll;
unordered_map<int,int>umap;

bool dfs(int val) {
    if (umap.find(val) != umap.end()) {
        if (umap[val] > 0) {
            umap[val]-=1;
            return true;
        }
    }
    if (val==1) {
        return false;
    }
    if (val%2==0) {
        return dfs(val/2) && dfs(val/2);
    } else {
        return dfs(val/2) && dfs((val/2)+1);
    }
}

void solve() {
    umap.clear();
    int n; int m; ll suma = 0; ll sumb = 0;
    cin >> n >> m;
    int a[n];
    
    for (int i=0; i < n; i++) {
        cin >> a[i];
        suma += a[i];
    }
    
    int b[m];
    for (int i=0; i < m; i++) {
        cin >> b[i];
        sumb += b[i];
    }

    if (suma != sumb) {
        cout << "No\n";
        return;
    }
    for (int i = 0; i < n; i++) {
        umap[a[i]]+=1;
    }

    for (int i = 0; i < m; i++) {
        if (!dfs(b[i])) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";

    umap.clear();
} 

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MOD = 1e9 + 7;

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

    vector<int>a(n),b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int j=0;j<m;j++) cin>>b[j];

    priority_queue<int> q1,q2;
    
    for(auto i:a) q1.push(i);
    for(auto i:b) q2.push(i);

    while(!q2.empty()){
        int curr=q2.top();
        q2.pop();

        if(q1.top()==curr){
            q1.pop();
            continue;
        }

        else if(q1.top()>curr){
            cout<<"NO"<<endl;
            return;
        }
        else if(q1.size()<q2.size()){
            cout<<"NO"<<endl;
            return;
        }
        q2.push(curr/2);
        q2.push((curr+1)/2);
    }
    if(q1.size()) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

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

    int t = 1;
    cin >> t;
    while (t--) solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define int long long
using namespace std;



void solve() {
	int l, r;
	cin >> l >> r;
	if (r - l == 2) {
		cout << l  << " " << l + 1 << " " << r << endl;
		return;
	}
	int idx = -1;
	int mid = 0;
	for (int i=30;i>=1;i--) {
		int a = l & (1 << i);
		int b = r & (1 << i);
		if (a == b) {
			idx = i;
			if (a > 0) mid += (1 << i);
		} else {
			break;
		}
	}
	mid += (1 << (idx-1));
	cout << l  << " " << mid - 1 << " " << mid << endl;
//	int mid = 1;
//	while (mid * 2 <= r) {
//		mid = mid * 2;
//	}
//	if (l + 1 < mid) {
//		cout << l  << " " << mid - 1 << " " << mid << endl;
//	} else if (l == mid - 1) {
//		cout << l  << " " << mid << " " << r << endl;
//	} else {
//		// l >= mid
//		
//		cout << endl;
//	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define int long long
using namespace std;



void solve() {
	int l, r;
	cin >> l >> r;
	int idx = -1;
	int mid = 0;
	for (int i=30;i>=1;i--) {
		int a = l & (1 << i);
		int b = r & (1 << i);
		if (a == b) {
			idx = i;
			if (a > 0) mid += (1 << i);
		} else {
			break;
		}
	}
	mid += (1 << (idx-1));
	if (mid - 1 == l) {
		cout << l  << " " << mid + 1 << " " << mid << endl;
	} else {
		cout << l  << " " << mid - 1 << " " << mid << endl;
	}
	
//	int mid = 1;
//	while (mid * 2 <= r) {
//		mid = mid * 2;
//	}
//	if (l + 1 < mid) {
//		cout << l  << " " << mid - 1 << " " << mid << endl;
//	} else if (l == mid - 1) {
//		cout << l  << " " << mid << " " << r << endl;
//	} else {
//		// l >= mid
//		
//		cout << endl;
//	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define int long long
using namespace std;



void solve() {
	int l, r;
	cin >> l >> r;
	if (r - l == 2) {
		cout << l  << " " << l + 1 << " " << r << endl;
		return;
	}
	int idx = -1;
	int mid = 0;
	for (int i=30;i>=1;i--) {
		int a = l & (1 << i);
		int b = r & (1 << i);
		if (a == b) {
			idx = i;
			if (a > 0) mid += (1 << i);
		} else {
			break;
		}
	}
	mid += (1 << (idx-1));
	cout << l  << " " << mid - 1 << " " << mid << endl;
//	int mid = 1;
//	while (mid * 2 <= r) {
//		mid = mid * 2;
//	}
//	if (l + 1 < mid) {
//		cout << l  << " " << mid - 1 << " " << mid << endl;
//	} else if (l == mid - 1) {
//		cout << l  << " " << mid << " " << r << endl;
//	} else {
//		// l >= mid
//		
//		cout << endl;
//	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define int long long
using namespace std;



void solve() {
	int l, r;
	cin >> l >> r;
	int idx = -1;
	int mid = 0;
	for (int i=30;i>=1;i--) {
		int a = l & (1 << i);
		int b = r & (1 << i);
		if (a == b) {
			idx = i;
			if (a > 0) mid += (1 << i);
		} else {
			break;
		}
	}
	mid += (1 << (idx-1));
	if (mid - 1 == l) {
		cout << l  << " " << mid + 1 << " " << mid << endl;
	} else {
		cout << l  << " " << mid - 1 << " " << mid << endl;
	}
	
//	int mid = 1;
//	while (mid * 2 <= r) {
//		mid = mid * 2;
//	}
//	if (l + 1 < mid) {
//		cout << l  << " " << mid - 1 << " " << mid << endl;
//	} else if (l == mid - 1) {
//		cout << l  << " " << mid << " " << r << endl;
//	} else {
//		// l >= mid
//		
//		cout << endl;
//	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define mapi map<int,int>
#define mapll map<ll,ll>
#define yes cout << "YES\n"
#define no cout<<"NO\n"
#define fori_n for(int i = 0; i<n; i++)
#define prans cout<<ans<<"\n";
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while(t--){
        ll l, r;
        cin >> l >> r;
        ll x = round(powl(2, (ll)log2l(r)));
        ll y = x, sum = 0;
        while(y){
            if(sum+y-1>=l && sum+y>=l && sum+y<=r){
                break;
            }
            if(sum+y<=r)
            sum+=y;
            y/=2;
        }
        x = sum+y-1;
        y+=sum;
        ll z;
        if(r==y){
            z = r-2;
        }
        else z = r;
        cout << x << " " << y << " " << z << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    
    for (int &x : a) cin >> x;

    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Place the smallest elements in the range [l, r]
    int sum = 0;
    for (int i = 0; i < (r - l + 1); i++) {
        sum += sorted_a[i];
    }

    cout << sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

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

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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    
    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Step 1: Sort the array to find the k smallest elements
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Step 2: Compute the minimum sum of the smallest (r - l + 1) elements
    int k = r - l + 1;
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += sorted_a[i];
    }

    // Output the result
    cout << min_sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Submission (verdict: Compilation error):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; r--; // Convert to 0-based indexing

    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Find the k smallest elements
    int k = r - l + 1;
    
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Smallest k elements
    vector<int> smallest_k(sorted_a.begin(), sorted_a.begin() + k);

    // Check if we can place them inside [l, r] using allowed swaps
    sort(smallest_k.begin(), smallest_k.end());

    // Compute the minimal sum possible in [l, r]
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += smallest_k[i];
    }

    cout << min_sum << "\n";
}

int main() {
    ios::sync_wit
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; r--; // Convert to 0-based indexing

    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Find the k smallest elements
    int k = r - l + 1;
    
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Smallest k elements
    vector<int> smallest_k(sorted_a.begin(), sorted_a.begin() + k);

    // Check if we can place them inside [l, r] using allowed swaps
    sort(smallest_k.begin(), smallest_k.end());

    // Compute the minimal sum possible in [l, r]
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += smallest_k[i];
    }

    cout << min_sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}



Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; // Convert to 0-based index
    r--; 

    vector<int> arr(n);
    for (int &x : arr) cin >> x;

    // Create brr: Sort the part of arr from l to n
    vector<int> brr = arr;
    sort(brr.begin() + l, brr.end());

    // Create crr: Sort the part of arr from 0 to r in descending order
    vector<int> crr = arr;
    sort(crr.begin(), crr.begin() + r + 1, greater<int>());

    // Compute sum of subarrays [l, r]
    long long sum_brr = 0, sum_crr = 0;
    for (int i = l; i <= r; i++) {
        sum_brr += brr[i];
        sum_crr += crr[i];
    }

    // Print the minimum sum
    cout << min(sum_brr, sum_crr) << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

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

Previous submission (verdict: Compilation error):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; r--; // Convert to 0-based indexing

    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Find the k smallest elements
    int k = r - l + 1;
    
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Smallest k elements
    vector<int> smallest_k(sorted_a.begin(), sorted_a.begin() + k);

    // Check if we can place them inside [l, r] using allowed swaps
    sort(smallest_k.begin(), smallest_k.end());

    // Compute the minimal sum possible in [l, r]
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += smallest_k[i];
    }

    cout << min_sum << "\n";
}

int main() {
    ios::sync_wit


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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; r--; // Convert to 0-based indexing

    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Find the k smallest elements
    int k = r - l + 1;
    
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Smallest k elements
    vector<int> smallest_k(sorted_a.begin(), sorted_a.begin() + k);

    // Check if we can place them inside [l, r] using allowed swaps
    sort(smallest_k.begin(), smallest_k.end());

    // Compute the minimal sum possible in [l, r]
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += smallest_k[i];
    }

    cout << min_sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

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

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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    
    for (int &x : a) cin >> x;

    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Place the smallest elements in the range [l, r]
    int sum = 0;
    for (int i = 0; i < (r - l + 1); i++) {
        sum += sorted_a[i];
    }

    cout << sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    
    vector<int> a(n);
    for (int &x : a) cin >> x;

    // Step 1: Sort the array to find the k smallest elements
    vector<int> sorted_a = a;
    sort(sorted_a.begin(), sorted_a.end());

    // Step 2: Compute the minimum sum of the smallest (r - l + 1) elements
    int k = r - l + 1;
    long long min_sum = 0;
    for (int i = 0; i < k; i++) {
        min_sum += sorted_a[i];
    }

    // Output the result
    cout << min_sum << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int maxN = 1e6 + 5;
const int Mod = 1e9 + 7;
const int LG = 21;
int n,mx,mx1,d[maxN];
bool avail[maxN];
vector<int> adj[maxN];
void input()
{
    cin >> n;
    for (int i = 0;i <= n;++i)
    {
        adj[i].clear();
        d[i] = 0;
        avail[i] = true;
    }
    mx = 0;mx1 = 0;
    for (int i = 1;i < n;++i)
    {
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        if (adj[mx].size() < adj[u].size()) mx = u;
        if (adj[mx].size() < adj[v].size()) mx = v;
    }
    avail[mx] = false;
}
void dfs(int u)
{
    avail[u] = false;
    for (int v : adj[u])
    {
        if (!avail[v] || v == mx || v == mx1) continue;
        d[u]++;
        dfs(v);
    }
}
void solve()
{
    mx1 = 0;
    if (n <= 2) {cout << 0 << "\n";return;}
    for (int i = 1;i <= n;++i) if (avail[i]) dfs(i);
    if (mx == 1) mx1 = n;
    else mx1 = 1;
    for (int i = 1;i <= n;++i) if (d[mx1] < d[i]) mx1 = i;
    fill(avail + 1,avail + n + 1,true);
    int res = 0;
    //cerr << mx << " " << mx1 << "aa\n";
    avail[mx] = false;
    avail[mx1] = false;
    for (int i = 1;i <= n;++i)
    {
        if (avail[i])
        {
            dfs(i);
            ++res;
        }
    }
    cout << res << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("1.inp","r",stdin);
//    freopen("1.out","w",stdout);
    int t;
    cin >> t;
    while (t--)
    {
        input();
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


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

void solve(int tc) {
    int l, r;
    cin >> l >> r;

    int res = 0;
    bool ok = false;
    for (int i = 30; i >= 0; --i) {
        if (!ok) {
            res |= (l >> i & 1) << i;
            if ((r >> i & 1) == 1 - (l >> i & 1)) {
                ok = true;
            }
        }
        else {
            res |= (1 - (r >> i & 1)) << i;
        }
    }

    cout << l << ' ' << res << ' ' << r << '\n';

    // cout << (l ^ res) + (res ^ r) + (r ^ l) << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve(i);
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

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

void solve(int tc) {
    int l, r;
    cin >> l >> r;

    int res = 0;
    bool ok = false;
    for (int i = 30; i >= 0; --i) {
        if (!ok) {
            res |= (l >> i & 1) << i;
            if ((r >> i & 1) == 1 - (l >> i & 1)) {
                ok = true;
            }
        }
        else {
            res |= (1 - (r >> i & 1)) << i;
        }
    }

    cout << l << ' ' << res << ' ' << r << '\n';

    // cout << (l ^ res) + (res ^ r) + (r ^ l) << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve(i);
    }
}

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

void solve(int tc) {
    int l, r;
    cin >> l >> r;

    int res = 0;
    bool ok = false;
    for (int i = 30; i >= 0; --i) {
        if (!ok) {
            res |= (l >> i & 1) << i;
            if ((r >> i & 1) == 1 - (l >> i & 1)) {
                ok = true;
                res |= 1 << i;
            }
        }
        else {
            res |= (1 - (r >> i & 1)) << i;
        }
    }

    cout << l << ' ' << res << ' ' << r << '\n';

    // cout << (l ^ res) + (res ^ r) + (r ^ l) << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve(i);
    }
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


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

string a,b,c;
int m,n,l;
vector<vector<vector<int>>> dp;
int rec(int level, int i, int j){
    if(level==l){
        return 0;
    }
    
    if(dp[level][i][j]!=-1){
        return dp[level][i][j];
    }
    
    int ans = 1e18;
    
    if(i<m && c[level]==a[i]){
        ans = min(ans,rec(level+1,i+1,j));
    }
    
    if(j<n && c[level]==b[j]){
        ans = min(ans,rec(level+1,i,j+1));
    }
    
    if(i<m) ans = min(ans,1+rec(level+1,i+1,j));
    if(j<n) ans = min(ans,1+rec(level+1,i,j+1));
    
    return dp[level][i][j] = ans;
}

void solve(){
    cin>>a>>b>>c;
    m = a.size();
    n = b.size();
    l = c.size();
    dp.clear();
    dp.assign(l+1,vector<vector<int>>(m+1,vector<int>(n+1,-1)));
    
    cout<<rec(0,0,0)<<endl;
}

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

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

string a,b,c;
int m,n,l;
vector<vector<vector<int>>> dp;
int rec(int level, int i, int j){
    if(level==l){
        return 0;
    }
    
    if(dp[level][i][j]!=-1){
        return dp[level][i][j];
    }
    
    int ans = 1e18;
    
    if(i<m && c[level]==a[i]){
        ans = min(ans,rec(level+1,i+1,j));
    }
    
    if(j<n && c[level]==b[j]){
        ans = min(ans,rec(level+1,i,j+1));
    }
    
    if(i<m) ans = min(ans,1+rec(level+1,i+1,j));
    if(j<n) ans = min(ans,1+rec(level+1,i,j+1));
    
    return dp[level][i][j] = ans;
}

void solve(){
    cin>>a>>b>>c;
    m = a.size();
    n = b.size();
    l = c.size();
    dp.clear();
    dp.assign(l+1,vector<vector<int>>(m+1,vector<int>(n+1,-1)));
    
    cout<<rec(0,0,0)<<endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

string a,b,c;
int m,n,l;
vector<vector<vector<int>>> dp;
int rec(int level, int i, int j){
    if(level==l){
        return 0;
    }
    
    if(dp[level%2][i%2][j%2]!=-1){
        return dp[level%2][i%2][j%2];
    }
    
    int ans = 1e18;
    
    if(i<m && c[level]==a[i]){
        ans = min(ans,rec(level+1,i+1,j));
    }
    
    if(j<n && c[level]==b[j]){
        ans = min(ans,rec(level+1,i,j+1));
    }
    
    if(i<m) ans = min(ans,1+rec(level+1,i+1,j));
    if(j<n) ans = min(ans,1+rec(level+1,i,j+1));
    
    return dp[level%2][i%2][j%2] = ans;
}

void solve(){
    cin>>a>>b>>c;
    m = a.size();
    n = b.size();
    l = c.size();
    dp.clear();
    dp.assign(4,vector<vector<int>>(4,vector<int>(4,-1)));
    
    cout<<rec(0,0,0)<<endl;
}

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

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

string a,b,c;
int m,n,l;
vector<vector<vector<int>>> dp;
int rec(int level, int i, int j){
    if(level==l){
        return 0;
    }
    
    if(dp[level%2][i%2][j%2]!=-1){
        return dp[level%2][i%2][j%2];
    }
    
    int ans = 1e18;
    
    if(i<m && c[level]==a[i]){
        ans = min(ans,rec(level+1,i+1,j));
    }
    
    if(j<n && c[level]==b[j]){
        ans = min(ans,rec(level+1,i,j+1));
    }
    
    if(i<m) ans = min(ans,1+rec(level+1,i+1,j));
    if(j<n) ans = min(ans,1+rec(level+1,i,j+1));
    
    return dp[level%2][i%2][j%2] = ans;
}

void solve(){
    cin>>a>>b>>c;
    m = a.size();
    n = b.size();
    l = c.size();
    dp.clear();
    dp.assign(4,vector<vector<int>>(4,vector<int>(4,-1)));
    
    cout<<rec(0,0,0)<<endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

string a,b,c;
int m,n,l;
vector<vector<vector<int>>> dp;
int rec(int level, int i, int j){
    if(level==l){
        return 0;
    }
    
    if(dp[level&2][i][j]!=-1){
        return dp[level&2][i][j];
    }
    
    int ans = 1e18;
    
    if(i<m && c[level]==a[i]){
        ans = min(ans,rec(level+1,i+1,j));
    }
    
    if(j<n && c[level]==b[j]){
        ans = min(ans,rec(level+1,i,j+1));
    }
    
    if(i<m) ans = min(ans,1+rec(level+1,i+1,j));
    if(j<n) ans = min(ans,1+rec(level+1,i,j+1));
    
    return dp[level&2][i][j] = ans;
}

void solve(){
    cin>>a>>b>>c;
    m = a.size();
    n = b.size();
    l = c.size();
    dp.clear();
    dp.assign(4,vector<vector<int>>(m+1,vector<int>(n+1,-1)));
    
    cout<<rec(0,0,0)<<endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}