ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

int getMax(vector<int> &edgeCount, vector<vector<int>> &adj) {
    int mx = 0;
    int ind;
    for(int i = 1; i <= N; i++) {
        if(edgeCount[i] >= mx) {
            mx = edgeCount[i];
            ind = i;
        }
    }
    edgeCount[ind] = -1;

    for(auto &u : adj[ind]) {
        edgeCount[u]--;
    }

    return mx;
}

void solve() {
    cin >> N;

    vector<vector<int>> adj(N+1);
    vector<int> edgeCount(N+1);
    for(int i = 0; i < N-1; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v); adj[v].push_back(u);
    }
    for(int i = 1; i<=N; i++) {
        edgeCount[i] = adj[i].size();
    }

    int ccCount = getMax(edgeCount, adj);
    ccCount += getMax(edgeCount, adj) - 1;

    cout << ccCount << endl;
}

int main() {
    int T; 
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

int getMax(vector<int> &edgeCount, vector<vector<int>> &adj) {
    int mx = 0;
    int ind;
    for(int i = 1; i <= N; i++) {
        if(edgeCount[i] >= mx) {
            mx = edgeCount[i];
            ind = i;
        }
    }
    edgeCount[ind] = -1e9;

    if(mx != 0) {
        for(auto &u : adj[ind]) {
            if(edgeCount[u] == -1e9)
                mx++;
            else 
                edgeCount[u]--;
        }
    }

    return mx;
}

void solve() {
    cin >> N;

    vector<vector<int>> adj(N+1);
    vector<int> edgeCount(N+1);
    for(int i = 0; i < N-1; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v); adj[v].push_back(u);
    }
    for(int i = 1; i<=N; i++) {
        edgeCount[i] = adj[i].size();
    }

    int ccCount = getMax(edgeCount, adj);
    ccCount += getMax(edgeCount, adj) - 1;

    cout << ccCount << endl;
}

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

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

void solve() {
    cin >> N;
    vector<vector<int>> adj(N+1);
    for(int i = 0; i < N-1; i++) {
        int a, b; 
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    multiset<int, greater<int>> moves;
    for(int i = 1; i <= N; i++) {
        moves.insert(adj[i].size() - 1);
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
        vector<int> removed;
        moves.erase(moves.find(adj[i].size() - 1));

        for(auto &u : adj[i]) {
            int cut = adj[u].size() - 1;
            moves.erase(moves.find(cut));
            moves.insert(cut - 1);
            removed.push_back(cut);
        }
        ans = max(ans, int(adj[i].size()) + int(*moves.begin()));

        moves.insert(adj[i].size() - 1);
        for(auto &r : removed) {
            moves.erase(moves.find(r - 1));
            moves.insert(r);
        }
    }
    cout << ans << endl;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

int getMax(vector<int> &edgeCount, vector<vector<int>> &adj) {
    int mx = 0;
    int ind;
    for(int i = 1; i <= N; i++) {
        if(edgeCount[i] >= mx) {
            mx = edgeCount[i];
            ind = i;
        }
    }
    edgeCount[ind] = -1;

    for(auto &u : adj[ind]) {
        edgeCount[u]--;
    }

    return mx;
}

void solve() {
    cin >> N;

    vector<vector<int>> adj(N+1);
    vector<int> edgeCount(N+1);
    for(int i = 0; i < N-1; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v); adj[v].push_back(u);
    }
    for(int i = 1; i<=N; i++) {
        edgeCount[i] = adj[i].size();
    }

    int ccCount = getMax(edgeCount, adj);
    ccCount += getMax(edgeCount, adj) - 1;

    cout << ccCount << endl;
}

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

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

int getMax(vector<int> &edgeCount, vector<vector<int>> &adj) {
    int mx = 0;
    int ind;
    for(int i = 1; i <= N; i++) {
        if(edgeCount[i] >= mx) {
            mx = edgeCount[i];
            ind = i;
        }
    }
    edgeCount[ind] = -1e9;

    for(auto &u : adj[ind]) {
        edgeCount[u]--;
    }

    return mx;
}

void solve() {
    cin >> N;

    vector<vector<int>> adj(N+1);
    vector<int> edgeCount(N+1);
    for(int i = 0; i < N-1; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v); adj[v].push_back(u);
    }
    for(int i = 1; i<=N; i++) {
        edgeCount[i] = adj[i].size();
    }

    int ccCount = getMax(edgeCount, adj);
    ccCount += getMax(edgeCount, adj) - 1;

    cout << ccCount << endl;
}

int main() {
    int T; 
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std; 
 
//KEVAL MORI//
 
#define Jay ios_base::sync_with_stdio(false);
#define Shree cin.tie(NULL);
#define Ram cout.tie(NULL);
#define read(n) long long int n;cin>>n;
#define tread(a,b) long long int a,b;cin>>a>>b;
#define thread(a,b,c) long long int a,b,c;cin>>a>>b>>c;
#define fread(a,b,c,d) long long int a,b,c,d; cin>>a>>b>>c>>d;
#define vread(v) for(int i=0;i<v.size();i++) cin>>v[i];
#define vvread(v) for(int i=0;i<v.size();i++) {for(int j=0;j<v[i].size();j++) cin>>v[i][j];}
#define lli long long int
#define ll long long
#define MOD 1000000007
#define ld long double
#define f(i,x,n) for(ll i = x; i < n; i++)
#define rf(i,x,n) for(ll i = x; i >= n; i--)
#define fr(i,m) for(auto &i:m)
#define vl vector<long long int>
#define vvl vector<vector<long long int>>
#define vs vector<string>
#define vpl vector<pair<long long int,long long int>>
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(a) (a).rbegin(), (a).rend()
#define rll(v) (v).begin(), (v).end(),greater<ll>()
#define sl set<long long int>
#define ss set<string>
#define mll map<long long int,long long int>
#define mss map<string,string>
#define msl map<string,long long int>
#define mls map<long long int,string>
#define pl pair<long long int,long long int>
#define fi first
#define se second
#define PI (3.141592653589)
#define maxar *max_element
#define minar *min_element
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) (all(x)), x.erase(unique(all(x)), x.end())
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define nope cout<<-1<<endl
#define pv(v) for (int i = 0; i < v.size(); i++) cout<<v[i]<<" "; 
#define pvv(v) for(int i=0;i<v.size();i++){ for(int j=0;j<v[i].size();j++) {cout<<v[i][j]<<" ";}cout<<endl;}
bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;}
bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}}
bool isInteger(double n){return floor(n)==n;}

void solve()
{
    read(n);
    vl a(n);
    vread(a);

    lli ans=accumulate(all(a),0LL),sum=0;

    lli limit=n-1;
    while(limit>0)
    {
        for (int i= 0; i < limit; i++) {
            a[i]=(a[i]-a[i+1]);
            sum+=abs(a[i]);
        }
        limit--;
        ans=max(sum,ans);
        sum=0;
    }
    cout<<ans<<endl;

}
int main()
{
    Jay Shree Ram

    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<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	ll n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	ll ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>=v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>=v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int 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<iostream>
#include<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	ll n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	ll ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l&&j>=l;i++,j--){
		if(v[j]>=v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n&&j>=l;i++,j--){
		if(v[j]>=v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	int n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	int ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	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<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	int n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	int ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>=v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>=v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int 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<iostream>
#include<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	ll n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	ll ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>=v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>=v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	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<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	int n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	int ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int 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<iostream>
#include<algorithm>
#include<vector> 
using namespace std;
typedef long long ll;
#define endl '\n'
//const int num=2e5+5;

void solve(){
	int n,l,r,sum=0;
	cin>>n>>l>>r;
	l--;
	r--;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i>=l&&i<=r){
			sum+=v[i];
		}
	}
	sort(v.begin(),v.begin()+l);
	sort(v.begin()+l,v.begin()+r+1);
	sort(v.begin()+r+1,v.end());
	int ans1=sum,ans2=sum;
	for(int i=0,j=r;i<l;i++,j--){
		if(v[j]>=v[i]){
			ans1-=v[j]-v[i];
		}else{
			break;
		}
	}
	for(int i=r+1,j=r;i<n;i++,j--){
		if(v[j]>=v[i]){
			ans2-=v[j]-v[i];
		}else{
			break;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;

#define ll long long

#define int long long

#define  ts ll t ;cin>>t ;while(t--)

#define endl "\n"

#define NO   "NO\n"

#define YES "YES\n"

//#define int long long

#define F   first

#define S    second

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int a[100005];

signed  main() {

   ts {

        int n , l , r;

        cin>>n>>l>>r;

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

            cin>>a[i];

        }

        sort(a,a+n);

        int len = r-l+1;

        int sum = 0;

        for (int i = 0 ;i<len ;i++)sum+=a[i];

        cout<<sum<<endl;

    }

}

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

using namespace std;

#define ll long long

#define int long long

#define  ts ll t ;cin>>t ;while(t--)

#define endl "\n"

#define NO   "NO\n"

#define YES "YES\n"

//#define int long long

#define F   first

#define S    second

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int n,l,r;

int a[100005],b[100005];

void solve() {

	int n, l , r;

	cin>>n>>l>>r;

	int len =r-l+1;

	l--;r--;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(a,a +r);

	sort(b+l,b+n);

	int sum1 =0 , sum2=0;

	for (int i = 0 ;i<len;i++)sum1+=a[i];

	for (int i = l ;i<len+l;i++)sum2+=b[i];

	cout<<min(sum1, sum2)<<endl;

}

signed main(){

	FAST

	ts{

		solve();

	}



}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;

#define ll long long

#define int long long

#define  ts ll t ;cin>>t ;while(t--)

#define endl "\n"

#define NO   "NO\n"

#define YES "YES\n"

//#define int long long

#define F   first

#define S    second

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int n,l,r;

int a[100005],b[100005];

void solve() {

	int n, l , r;

	cin>>n>>l>>r;

	int len =r-l+1;

	l--;r--;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(a,a +r);

	sort(b+l,b+n);

	int sum1 =0 , sum2=0;

	for (int i = 0 ;i<len;i++)sum1+=a[i];

	for (int i = l ;i<len+l;i++)sum2+=b[i];

	cout<<min(sum1, sum2)<<endl;

}

signed main(){

	FAST

	ts{

		solve();

	}



}

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

using namespace std;

#define ll long long

#define int long long

#define  ts ll t ;cin>>t ;while(t--)

#define endl "\n"

#define NO   "NO\n"

#define YES "YES\n"

//#define int long long

#define F   first

#define S    second

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int n,l,r;

int a[100005],b[100005];

void solve() {

	int n, l , r;

	cin>>n>>l>>r;

	int len =r-l+1;

	l--;r--;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(a,a +r+1);

	sort(b+l,b+n);

	int sum1 =0 , sum2=0;

	for (int i = 0 ;i<len;i++)sum1+=a[i];

	for (int i = l ;i<len+l;i++)sum2+=b[i];

	cout<<min(sum1, sum2)<<endl;

}

signed main(){

	FAST

	ts{

		solve();

	}



}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

using namespace std;

#define ll long long

#define int long long

#define  ts ll t ;cin>>t ;while(t--)

#define endl "\n"

#define NO   "NO\n"

#define YES "YES\n"

//#define int long long

#define F   first

#define S    second

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int a[100005];

signed  main() {

   ts {

        int n , l , r;

        cin>>n>>l>>r;

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

            cin>>a[i];

        }

        sort(a,a+n);

        int len = r-l+1;

        int sum = 0;

        for (int i = 0 ;i<len ;i++)sum+=a[i];

        cout<<sum<<endl;

    }

}
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
def min_changes_needed(t, test_cases):
    results = []
    
    for a, b, c in test_cases:
        n, m = len(a), len(b)
        dp = [[0] * (m + 1) for _ in range(n + 1)]
        
        for i in range(n + 1):
            for j in range(m + 1):
                c_index = i + j - 1
                if i == 0 and j == 0:
                    continue
                if c_index >= len(c):
                    continue
                if i > 0 and a[i - 1] == c[c_index]:
                    dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1)
                if j > 0 and b[j - 1] == c[c_index]:
                    dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1)
        max_matched = dp[n][m]
        changes_needed = (n + m) - max_matched
        results.append(changes_needed)
    return results
t = 7 
test_cases = [
    ("a", "b", "cb"),
    ("ab", "cd", "acbd"),
    ("ab", "ba", "aabb"),
    ("xxx", "yyy", "xyxyxy"),
    ("a", "bcd", "decf"),
    ("codes", "horse", "codeforces"),
    ("egg", "annie", "egaegaeg")
]
outputs = min_changes_needed(t, test_cases)
for output in outputs:
    print(output)

Submission (verdict: Accepted):
def min_changes(a, b, c):
    n, m = len(a), len(b)
    dp = [[float('inf')] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 0

    for i in range(n + 1):
        for j in range(m + 1):
            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]))
    
    return dp[n][m]

t = int(input())
for _ in range(t):
    a = input().strip()
    b = input().strip()
    c = input().strip()
    print(min_changes(a, b, c))
Problem: 2050E - Three Strings
Language: Python 3


Submission (verdict: Runtime error on test 1):
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e54c80f1-8818-4816-ba60-95d17a7b366e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "0\n",
      "3\n",
      "0\n",
      "4\n",
      "8\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "def min_changes_needed(t, test_cases):\n",
    "    results = []\n",
    "    \n",
    "    for a, b, c in test_cases:\n",
    "        n, m = len(a), len(b)\n",
    "        dp = [[0] * (m + 1) for _ in range(n + 1)]\n",
    "        \n",
    "        for i in range(n + 1):\n",
    "            for j in range(m + 1):\n",
    "                if i + j == 0:\n",
    "                    continue\n",
    "                c_index = i + j - 1\n",
    "                if i > 0 and c_index < len(c) and a[i - 1] == c[c_index]:\n",
    "                    dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1)\n",
    "                if j > 0 and c_index < len(c) and b[j - 1] == c[c_index]:\n",
    "                    dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1)\n",
    "        \n",
    "        max_matched = dp[n][m]\n",
    "        changes_needed = (n + m) - max_matched\n",
    "        results.append(changes_needed)\n",
    "    \n",
    "    return results\n",
    "\n",
    "# Example Input\n",
    "t = 7 \n",
    "test_cases = [\n",
    "    (\"a\", \"b\", \"cb\"),\n",
    "    (\"ab\", \"cd\", \"acbd\"),\n",
    "    (\"ab\", \"ba\", \"aabb\"),\n",
    "    (\"xxx\", \"yyy\", \"xyxyxy\"),\n",
    "    (\"a\", \"bcd\", \"decf\"),\n",
    "    (\"codes\", \"horse\", \"codeforces\"),\n",
    "    (\"egg\", \"annie\", \"egaegaeg\")\n",
    "]\n",
    "\n",
    "# Function call\n",
    "outputs = min_changes_needed(t, test_cases)\n",
    "for output in outputs:\n",
    "    print(output)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d7d4f76-4765-403f-9d8d-65050c7f584e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

int main() {
	// your code goes here
int t;
cin>>t;
while(t--)
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ctr=0; int ctr2=0;
    for(int i=0;i<n-1;i++)
    {
        int sub=min(v[i],v[i+1]);
        v[i]=v[i]-sub;
        v[i+1]=v[i+1]-sub;
        if(v[i]>=v[i+1])
        {
            cout<<"NO"<<endl;
            break;
        }
        else ctr++;
    }
    if(ctr>0)
    cout<<"YES"<<endl;
   
}
}


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

int main() {
	// your code goes here
int t;
cin>>t;
while(t--)
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ctr=0; int ctr2=0;
    for(int i=0;i<n-1;i++)
    {
        int sub=min(v[i],v[i+1]);
        v[i]=v[i]-sub;
        v[i+1]=v[i+1]-sub;
        if(v[i]>=v[i+1])
        {
            cout<<"NO"<<endl;
            break;
        }
        else ctr++;
    }
    if(ctr==n-1)
    cout<<"YES"<<endl;
   
}
}