ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int k2 = k;
        int a[n];
        map <int, int> e;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            e[a[i]]++;
        }
        int ans = e.size();
        for(auto x : e)
        {
            if(k >= x.second)
            {
                ans--;
                k -= x.second;
            }
        }
        if(k2 >= (e.size() - 1)) ans = 1;
        std::cout << ans << '\n';
    }
    return 0;
}

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int k2 = k;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        vector <int> e {1};
        for(int i = 1; i < n; i++)
        {
            if(a[i] == a[i - 1]) e.back()++;
            else e.push_back(1);
        }
        int ans = e.size();
        sort(e.begin(), e.end());
        for(auto x : e)
        {
            if(k >= x)
            {
                ans--;
                k -= x;
            }
        }
        if(k2 >= (n - 1)) ans = 1;
        std::cout << ans << '\n';
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int k2 = k;
        int a[n];
        map <int, int> e;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            e[a[i]]++;
        }
        int ans = e.size();
        for(auto x : e)
        {
            if(k >= x.second)
            {
                ans--;
                k -= x.second;
            }
        }
        if(k2 >= (n - 1)) ans = 1;
        std::cout << ans << '\n';
    }
    return 0;
}

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int k2 = k;
        int a[n];
        map <int, int> e;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            e[a[i]]++;
        }
        int ans = e.size();
        for(auto x : e)
        {
            if(k >= x.second)
            {
                ans--;
                k -= x.second;
            }
        }
        if(k2 >= (e.size() - 1)) ans = 1;
        std::cout << ans << '\n';
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


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

#include<vector>

#include<map>

#include <unordered_map>

#include<set>

#include <unordered_set>    

#include<string>

#include<algorithm>

using namespace std;

typedef long long ll;

#define pb push_back

#define in insert

#define vi vector <int>

#define vpi vector<pair<int,int>>

#define mii map<int,int>

#define si set <int>



#define fori(n) for(int i=0;i<n;i++)

#define forab(i,a,b) for(int i=a;i<b;i++)

#define all(v) (v.begin(),v.end())

#define endl "\n"

#define look(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define haa cout<<"YES"<<endl;

#define naa cout<<"NO"<<endl;



void disp(vi v)

{

    for (auto x:v) cout<<x<<" ";

    cout<<endl;

}

void disp(int a[],int n)

{

    fori(n) cout<<a[i]<<" ";

    cout<<endl;

}

int main()

{

 // ios_base::sync_with_stdio(false);

 // cin.tie(NULL);

int t;cin>>t;

while(t--)

{

    int n,x,y;

    cin>>n>>x>>y;

    vector<int> a(n,-1);

    a[0]=0;

    int mod=n%3;

    for (int i=1;i<n-mod;i++){

        if(i+1<n && a[i+1]!=-1){

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

            if(a[i]==a[i+1]){

                a[i]=a[i+1]%3;

            }

        }

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

       if(i+1==x){

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

       }

    }

    if(mod==1){

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

    }

    else{

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

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



    }

    disp(a);

    

}

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>

#include<vector>

#include<map>

#include <unordered_map>

#include<set>

#include <unordered_set>    

#include<string>

#include<algorithm>

using namespace std;

typedef long long ll;

#define pb push_back

#define in insert

#define vi vector <int>

#define vpi vector<pair<int,int>>

#define mii map<int,int>

#define si set <int>



#define fori(n) for(int i=0;i<n;i++)

#define forab(i,a,b) for(int i=a;i<b;i++)

#define all(v) (v.begin(),v.end())

#define endl "\n"

#define look(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define haa cout<<"YES"<<endl;

#define naa cout<<"NO"<<endl;



void disp(vi v)

{

    for (auto x:v) cout<<x<<" ";

    cout<<endl;

}

void disp(int a[],int n)

{

    fori(n) cout<<a[i]<<" ";

    cout<<endl;

}

int main()

{

 // ios_base::sync_with_stdio(false);

 // cin.tie(NULL);

int t;cin>>t;

while(t--)

{

    int n,x,y;

    cin>>n>>x>>y;

    vector<int> a(n,-1);

    a[0]=0;

    int mod=n%3;

    for (int i=1;i<n-mod;i++){

        if(i+1<n && a[i+1]!=-1){

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

            if(a[i]==a[i+1]){

                a[i]=a[i+1]%3;

            }

        }

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

       if(i+1==x){

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

       }

    }

    if(mod==1){

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

    }

    else{

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

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



    }

    disp(a);

    

}

}

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

#include<vector>

#include<map>

#include <unordered_map>

#include<set>

#include <unordered_set>    

#include<string>

#include<algorithm>

using namespace std;

typedef long long ll;

#define pb push_back

#define in insert

#define vi vector <int>

#define vpi vector<pair<int,int>>

#define mii map<int,int>

#define si set <int>



#define fori(n) for(int i=0;i<n;i++)

#define forab(i,a,b) for(int i=a;i<b;i++)

#define all(v) (v.begin(),v.end())

#define endl "\n"

#define look(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define haa cout<<"YES"<<endl;

#define naa cout<<"NO"<<endl;



void disp(vi v)

{

    for (auto x:v) cout<<x<<" ";

    cout<<endl;

}

void disp(int a[],int n)

{

    fori(n) cout<<a[i]<<" ";

    cout<<endl;

}

int main()

{

 // ios_base::sync_with_stdio(false);

 // cin.tie(NULL);

int t;cin>>t;

while(t--)

{

    int n,x,y;

    cin>>n>>x>>y;

    vector<int> a(n,-1);

    a[0]=0;

    int mod=n%3;

    for (int i=1;i<n-mod;i++){

        if(i+1<n && a[i+1]!=-1){

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

            if(a[i]==a[i+1]){

                a[i]=a[i+1]%3;

            }

        }

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

       if(i+1==x){

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

       }

    }

    if(mod==1){

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

        fori(n){

            a[i]=(a[i+1])%3;

        }

    }

    else{

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

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



    }

    disp(a);

    

}

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>

#include<vector>

#include<map>

#include <unordered_map>

#include<set>

#include <unordered_set>    

#include<string>

#include<algorithm>

using namespace std;

typedef long long ll;

#define pb push_back

#define in insert

#define vi vector <int>

#define vpi vector<pair<int,int>>

#define mii map<int,int>

#define si set <int>



#define fori(n) for(int i=0;i<n;i++)

#define forab(i,a,b) for(int i=a;i<b;i++)

#define all(v) (v.begin(),v.end())

#define endl "\n"

#define look(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define haa cout<<"YES"<<endl;

#define naa cout<<"NO"<<endl;



void disp(vi v)

{

    for (auto x:v) cout<<x<<" ";

    cout<<endl;

}

void disp(int a[],int n)

{

    fori(n) cout<<a[i]<<" ";

    cout<<endl;

}

int main()

{

 // ios_base::sync_with_stdio(false);

 // cin.tie(NULL);

int t;cin>>t;

while(t--)

{

    int n,x,y;

    cin>>n>>x>>y;

    vector<int> a(n,-1);

    a[0]=0;

    int mod=n%3;

    for (int i=1;i<n-mod;i++){

        if(i+1<n && a[i+1]!=-1){

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

            if(a[i]==a[i+1]){

                a[i]=a[i+1]%3;

            }

        }

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

       if(i+1==x){

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

       }

    }

    if(mod==1){

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

        fori(n){

            a[i]=(a[i+1])%3;

        }

    }

    else{

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

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



    }

    disp(a);

    

}

}

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

#include<vector>

#include<map>

#include <unordered_map>

#include<set>

#include <unordered_set>    

#include<string>

#include<algorithm>

using namespace std;

typedef long long ll;

#define pb push_back

#define in insert

#define vi vector <int>

#define vpi vector<pair<int,int>>

#define mii map<int,int>

#define si set <int>



#define fori(n) for(int i=0;i<n;i++)

#define forab(i,a,b) for(int i=a;i<b;i++)

#define all(v) (v.begin(),v.end())

#define endl "\n"

#define look(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define haa cout<<"YES"<<endl;

#define naa cout<<"NO"<<endl;



void disp(vi v)

{

    for (auto x:v) cout<<x<<" ";

    cout<<endl;

}

void disp(int a[],int n)

{

    fori(n) cout<<a[i]<<" ";

    cout<<endl;

}

int main()

{

 // ios_base::sync_with_stdio(false);

 // cin.tie(NULL);

int t;cin>>t;

while(t--)

{

    int n,x,y;

    cin>>n>>x>>y;

    

    vector<int> ans(n);

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

    if (n % 2 || (x - y) % 2 == 0)

        ans[x-1] = 2;

    disp(ans);

    

}

}
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 4):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
for x in a:
    k = a.index(x)
    l = pom.index(x)
    if l == k:
        continue
    for j in range(l, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in res and (pom[j],pom[i]) not in res:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
for x in a:
    k = a.index(x)
    l = pom.index(x)
    if l == k:
        continue
    for j in range(l, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in res and (pom[j],pom[i]) not in res:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)

Submission (verdict: Time limit exceeded on test 38):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
for x in a:
    k = a.index(x)
    l = pom.index(x)
    for j in range(l, n-1):
        if (pom[j+1], pom[j]) not in res:
            res.append((pom[j+1], pom[j]))
            pom[j], pom[j+1] = pom[j+1], pom[j]
        else:
            break
    j = pom.index(x)
    for j in range(j, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in res and (pom[j],pom[i]) not in res:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 38):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
for x in a:
    k = a.index(x)
    l = pom.index(x)
    for j in range(l, n-1):
        if (pom[j+1], pom[j]) not in res:
            res.append((pom[j+1], pom[j]))
            pom[j], pom[j+1] = pom[j+1], pom[j]
        else:
            break
    j = pom.index(x)
    for j in range(j, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in res and (pom[j],pom[i]) not in res:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)

Submission (verdict: Wrong answer on test 1):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
vis = set()
for x in a:
    k = a.index(x)
    l = pom.index(x)
    for j in range(l, n-1):
        if (pom[j+1], pom[j]) not in vis:
            res.append((pom[j+1], pom[j]))
            vis.add((pom[j+1], pom[j]))
            pom[j], pom[j+1] = pom[j+1], pom[j]
        else:
            break
    j = pom.index(x)
    for j in range(j, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in vis and (pom[j],pom[i]) not in vis:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))
        vis.add((pom[i],pom[j]))
        vis.add((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
vis = set()
for x in a:
    k = a.index(x)
    l = pom.index(x)
    for j in range(l, n-1):
        if (pom[j+1], pom[j]) not in vis:
            res.append((pom[j+1], pom[j]))
            vis.add((pom[j+1], pom[j]))
            pom[j], pom[j+1] = pom[j+1], pom[j]
        else:
            break
    j = pom.index(x)
    for j in range(j, k, -1):
        res.append((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in vis and (pom[j],pom[i]) not in vis:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))
        vis.add((pom[i],pom[j]))
        vis.add((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)

Submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

res = []
pom = [ i for i in range(1, n+1)]
vis = set()
for x in a:
    k = a.index(x)
    l = pom.index(x)
    for j in range(l, n-1):
        if (pom[j+1], pom[j]) not in vis:
            res.append((pom[j+1], pom[j]))
            vis.add((pom[j+1], pom[j]))
            pom[j], pom[j+1] = pom[j+1], pom[j]
        else:
            break
    j = pom.index(x)
    for j in range(j, k, -1):
        res.append((pom[j], pom[j-1]))
        vis.add((pom[j], pom[j-1]))
        pom[j], pom[j-1] = pom[j-1], pom[j]

for i in range(n-1, 0, -1):
    j = i - 1
    if (pom[i],pom[j]) not in vis and (pom[j],pom[i]) not in vis:
        res.append((pom[i],pom[j]))
        res.append((pom[j],pom[i]))
        vis.add((pom[i],pom[j]))
        vis.add((pom[j],pom[i]))


print(len(res))
for x, y in res:
    print(x, y)
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

            else

                ans[i][0] = ans[i - 1][0];

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

            else

                ans[0][i] = ans[0][i - 1];

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        for (vector<int> i : ans)

        {

            for (int j : i)

                cout << j;

            cout << '\n';

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}













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

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

            else

                ans[i][0] = ans[i - 1][0];

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

            else

                ans[0][i] = ans[0][i - 1];

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()];

    }

}













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

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size(), vector<int>(b.size(), 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()];

    }

}













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

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()];

    }

}