ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: Java 21


Submission (verdict: Time limit exceeded on test 6):
import java.io.*;
import java.util.*;

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i = c.length;
                }
            }

            System.out.println(new String(c));
        }
    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}
Problem: 2050D - Digital string maximization
Language: Java 21

Previous submission (verdict: Time limit exceeded on test 6):
import java.io.*;
import java.util.*;

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i = c.length;
                }
            }

            System.out.println(new String(c));
        }
    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}

Submission (verdict: Time limit exceeded on test 6):
import java.io.*;
import java.util.*;

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i = findLast(c);
                }
            }

            System.out.println(new String(c));
        }
    }

    public static int findLast(char[] c) {
        for (int i = c.length - 1; i > 0; i--) {
            if (c[i] > c[i - 1] + 1) {
                return i + 1;
            }
        }
        return c.length;
    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}
Problem: 2050D - Digital string maximization
Language: Java 21

Previous submission (verdict: Time limit exceeded on test 6):
import java.io.*;
import java.util.*;

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i = findLast(c);
                }
            }

            System.out.println(new String(c));
        }
    }

    public static int findLast(char[] c) {
        for (int i = c.length - 1; i > 0; i--) {
            if (c[i] > c[i - 1] + 1) {
                return i + 1;
            }
        }
        return c.length;
    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}

Submission (verdict: Accepted):
import java.io.*;
import java.util.*;

public class DigitalStringMaximization {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());

        while (t-- > 0) {
            tokenizer = new StringTokenizer(in.readLine());
            char[] c = tokenizer.nextToken().toCharArray();

            for (int i = c.length - 1; i > 0; i--) {
                if (c[i] > c[i - 1] + 1) {
                    operation(c, i);
                    i += 9;
                    if (i > c.length) {
                        i = c.length;
                    }
                }
            }

            System.out.println(new String(c));
        }
    }

//    public static int findLast(char[] c) {
//        for (int i = c.length - 1; i > 0; i--) {
//            if (c[i] > c[i - 1] + 1) {
//                return i + 1;
//            }
//        }
//        return c.length;
//    }

    public static void operation(char[] c, int i) {
        int cur = c[i];
        int left = c[i - 1];
        c[i - 1] = (char) (cur - 1);
        c[i] = (char) left;
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(a[1] < 0) f = 1;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] <= a[i + 1])
			{
				a[i + 1] -= a[i];
				a[i] = 0;
			}
		}
		int f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] <= a[i + 1]) continue;
			f = 1;
		}
		
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c == 1 && n == 2) f = 1;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(a[1] < 0) f = 1;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
typedef pair<ll, string>PIS;
const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e9 + 7;

int a[N];
int main()
{
	int t;
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> a[i];
		}
		for(int i = 1; i <= n - 1; i ++)
		{
			a[i] = a[i + 1] - a[i];
		}
		int c = 0, f = 0;
		for(int i = 1; i <= n - 1; i ++)
		{
			if(a[i] < 0) c ++;
			else c = 0;
			if(c == 1 && n == 2) f = 1;
			if(c >= 2) f = 1;
		}
		if(f) puts("No");
		else puts("Yes");
	}
	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;
int mo = 998244353;

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

    vector<int> a(n + 1),b(m + 1);
    map<int,int> mp1,mp2;
    int sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        sum1 += a[i];
        mp1[a[i]] ++;
    }

    sort(a.begin() + 1,a.end());

    for(int i=1;i<=m;i++){
        cin >> b[i];
        sum2 += b[i];
        mp2[b[i]] ++;
    } 

    sort(b.begin() + 1,b.end());

    if(sum1 != sum2)
    {
        cout << "No\n";
        return;
    }

    for(int i=1;i<=m;i++)
    {
        if(mp1.count(b[i]))
        {
            mp1[b[i]]--;

            if(mp1[b[i]] == 0)
            {
                mp1.erase(b[i]);
            }
            continue;
        }
        
        auto dfs = [&](auto dfs,int x) ->bool
        {
            if(mp1.count(x))
            {
                mp1[x]--;

                if(mp1[b[i]] == 0)
                {
                    mp1.erase(b[i]);
                }

                return true;
            }

            if(mp1.size() == 0 || (*mp1.begin()).first > x)
            {
                return false;
            }

            bool ok1 = dfs(dfs,x/2);
            bool ok2 = 0;
            if(x % 2 == 0) ok2 =  dfs(dfs,x/2);
            else ok2 =  dfs(dfs,x/2 + 1);

            return (ok1 & ok2);
        };

        bool ok = dfs(dfs,b[i]);

        if(ok == false)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

}

signed main()
{
    int t = 1;
    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>
#define int long long
using namespace std;
int mo = 998244353;

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

    vector<int> a(n + 1),b(m + 1);
    map<int,int> mp1,mp2;
    int sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        sum1 += a[i];
        mp1[a[i]] ++;
    }

    sort(a.begin() + 1,a.end());

    for(int i=1;i<=m;i++){
        cin >> b[i];
        sum2 += b[i];
    } 

    sort(b.begin() + 1,b.end());

    if(sum1 != sum2)
    {
        cout << "No\n";
        return;
    }

    for(int i=1;i<=m;i++)
    {
        auto dfs = [&](auto dfs,int x) ->bool
        {
            if(mp1.count(x))
            {
                mp1[x]--;

                if(mp1[b[i]] == 0)
                {
                    mp1.erase(b[i]);
                }

                return true;
            }

            if(mp1.size() == 0 || (*mp1.begin()).first > x)
            {
                return false;
            }

            bool ok1 = dfs(dfs,x/2);
            bool ok2 = 0;
            if(x % 2 == 0) ok2 =  dfs(dfs,x/2);
            else ok2 =  dfs(dfs,x/2 + 1);

            return (ok1 & ok2);
        };

        bool ok = dfs(dfs,b[i]);

        if(ok == false)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

}

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

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

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

    vector<int> a(n + 1),b(m + 1);
    map<int,int> mp1,mp2;
    int sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        sum1 += a[i];
        mp1[a[i]] ++;
    }

    sort(a.begin() + 1,a.end());

    for(int i=1;i<=m;i++){
        cin >> b[i];
        sum2 += b[i];
    } 

    sort(b.begin() + 1,b.end());

    if(sum1 != sum2)
    {
        cout << "No\n";
        return;
    }

    for(int i=1;i<=m;i++)
    {
        auto dfs = [&](auto dfs,int x) ->bool
        {
            if(mp1.count(x))
            {
                mp1[x]--;

                if(mp1[x] == 0)
                {
                    mp1.erase(x);
                }

                return true;
            }

            if(mp1.size() == 0 || (*mp1.begin()).first > x)
            {
                return false;
            }

            bool ok1 = dfs(dfs,x/2);
            bool ok2 = 0;
            if(x % 2 == 0) ok2 =  dfs(dfs,x/2);
            else ok2 =  dfs(dfs,x/2 + 1);

            return (ok1 & ok2);
        };

        bool ok = dfs(dfs,b[i]);

        if(ok == false)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

}

signed main()
{
    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
    
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

int minChanges(string a, string b, string c) {
    int n = a.size();
    int m = b.size();

    // dp table of size (n+1) x (m+1)
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    // Fill the dp table
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i > 0 && a[i - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1);
            }
            if (j > 0 && b[j - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
            }
            if (i > 0 && j > 0) {
                dp[i][j] = max({dp[i][j], dp[i][j - 1], dp[i-1][j]});
            }
        }
    }

    // Maximum matching is dp[n][m]
    int maxMatching = dp[n][m];

    // Minimum changes required
    return (n + m) - maxMatching;
}

int main() {
	int t; cin >> t;
	while(t--){
	    string a, b, c;
	
	    cin >> a;
	    cin >> b;
	    cin >> c;
	
	    int result = minChanges(a, b, c);
	    cout << result << endl;
	}

    return 0;
}


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

int minChanges(string a, string b, string c) {
    int n = a.size();
    int m = b.size();

    // dp table of size (n+1) x (m+1)
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    // Fill the dp table
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i > 0 && a[i - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1);
            }
            if (j > 0 && b[j - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
            }
            if (i > 0 && j > 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
            }
        }
    }

    // Maximum matching is dp[n][m]
    int maxMatching = dp[n][m];

    // Minimum changes required
    return (n + m) - maxMatching;
}

int main() {
    string a, b, c;
    cout << "Enter string a: ";
    cin >> a;
    cout << "Enter string b: ";
    cin >> b;
    cout << "Enter string c: ";
    cin >> c;

    // Check if c's length matches the combined length of a and b
    if (c.size() != a.size() + b.size()) {
        cout << "Invalid input: length of c must be equal to the sum of lengths of a and b." << endl;
        return 1;
    }

    int result = minChanges(a, b, c);
    cout << "Minimum changes required: " << result << endl;

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


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

int minChanges(string a, string b, string c) {
    int n = a.size();
    int m = b.size();

    // dp table of size (n+1) x (m+1)
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    // Fill the dp table
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i > 0 && a[i - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1);
            }
            if (j > 0 && b[j - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
            }
            if (i > 0 && j > 0) {
                dp[i][j] = max({dp[i][j], dp[i][j - 1], dp[i-1][j]});
            }
        }
    }

    // Maximum matching is dp[n][m]
    int maxMatching = dp[n][m];

    // Minimum changes required
    return (n + m) - maxMatching;
}

int main() {
	int t; cin >> t;
	while(t--){
	    string a, b, c;
	
	    cin >> a;
	    cin >> b;
	    cin >> c;
	
	    int result = minChanges(a, b, c);
	    cout << result << endl;
	}

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

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

int minChanges(string a, string b, string c) {
    int n = a.size();
    int m = b.size();

    // dp table of size (n+1) x (m+1)
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    // Fill the dp table
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i > 0 && a[i - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1);
            }
            if (j > 0 && b[j - 1] == c[i + j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
            }
            if (i > 0 && j > 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
            }
        }
    }

    // Maximum matching is dp[n][m]
    int maxMatching = dp[n][m];

    // Minimum changes required
    return (n + m) - maxMatching;
}

int main() {
    string a, b, c;
    cout << "Enter string a: ";
    cin >> a;
    cout << "Enter string b: ";
    cin >> b;
    cout << "Enter string c: ";
    cin >> c;

    // Check if c's length matches the combined length of a and b
    if (c.size() != a.size() + b.size()) {
        cout << "Invalid input: length of c must be equal to the sum of lengths of a and b." << endl;
        return 1;
    }

    int result = minChanges(a, b, c);
    cout << "Minimum changes required: " << result << endl;

    return 0;
}


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

int dp[1006][1006];
void solve(){
	memset(dp,0,sizeof(dp));
	string a,b;
	string s;
	cin>>a>>b>>s;
	for(int i=0;i<=a.size();i++){
		for(int j=0;j<=b.size();j++){
			if(i){
				dp[i][j]=max(dp[i][j],dp[i-1][j]+(s[i+j-1]==a[i-1]?1:0));
			}
			if(j){
				dp[i][j]=max(dp[i][j],dp[i][j-1]+(s[i+j-1]==b[j-1]?1:0));
			}
		}
	}
	cout<<s.size()-dp[a.size()][b.size()]<<endl;
}
int main(){
	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<iostream>
#include<bits/stdc++.h>
using namespace std;


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

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

   if(n==1)
   {
    cout << a[0] << endl;
    return;
   }
    int ans = accumulate(a.begin(),a.end(),0LL);
    vector<long> b = a;
   while(b.size()>1)
   {
    vector<long> temp;
    for(int i=1;i<b.size();i++)
    {
        temp.push_back(b[i] - b[i-1]);
    }
    b = temp;
   }

   cout << max(1LL*ans,1LL*abs(b[0])) << endl;

    
}
int main(){
    int t;
    cin >> t;

    while(t--)
    {
        solve();
    }
}