ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
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;
void solve(){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n,0);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    for(ll i=0;i<n;i++)ans+=a[i];
    while(a.size()>2){
        vector<ll>t;
        for(ll i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n,0);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    for(ll i=0;i<n;i++)ans+=a[i];
    while(a.size()>2){
        vector<ll>t;
        ll sum=0;
        for(ll i=1;i<a.size();i++){
            t.push_back(a[i]-a[i-1]);
            sum+=a[i]-a[i-1];
        }
        ans=max(ans,sum);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}
Problem: 2062C - Cirno and Operations
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;
void solve(){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n,0);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    for(ll i=0;i<n;i++)ans+=a[i];
    while(a.size()>2){
        vector<ll>t;
        ll sum=0;
        for(ll i=1;i<a.size();i++){
            t.push_back(a[i]-a[i-1]);
            sum+=a[i]-a[i-1];
        }
        ans=max(ans,sum);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n,0);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    for(ll i=0;i<n;i++)ans+=a[i];
    while(a.size()>2){
        vector<ll>t;
        ll sum=0;
        for(ll i=1;i<a.size();i++){
            t.push_back(a[i]-a[i-1]);
            sum+=a[i]-a[i-1];
        }
        ans=max(ans,max(sum,-sum));
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}
Problem: 2062C - Cirno and Operations
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;
ll ans=-1e18;
void dfs(vector<ll>a){
    
}
void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n,0);
    ans=-1e18;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    ll sum=0;
    for(int i=0;i<n;i++)sum+=a[i];
    ans=max(ans,sum);
    while(a.size()>2){
        vector<ll>t;
        for(int i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=-1e18;
void dfs(vector<ll>a){
    
}
void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n,0);
    ans=-1e18;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    ll sum=0;
    for(int i=0;i<n;i++)sum+=a[i];
    ans=max(ans,sum);
    vector<ll>b=a;
    while(a.size()>2){
        vector<ll>t;
        for(int i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    reverse(b.begin(),b.end());
    a=b;
    while(a.size()>2){
        vector<ll>t;
        for(int i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}
Problem: 2062C - Cirno and Operations
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;
ll ans=-1e18;
void dfs(vector<ll>a){
    
}
void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n,0);
    ans=-1e18;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    ll sum=0;
    for(int i=0;i<n;i++)sum+=a[i];
    ans=max(ans,sum);
    vector<ll>b=a;
    while(a.size()>2){
        vector<ll>t;
        for(int i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    reverse(b.begin(),b.end());
    a=b;
    while(a.size()>2){
        vector<ll>t;
        for(int i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n,0);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0]<<"\n";
        return ;
    }
    for(ll i=0;i<n;i++)ans+=a[i];
    while(a.size()>2){
        vector<ll>t;
        for(ll i=1;i<a.size();i++)t.push_back(a[i]-a[i-1]);
        a=t;
    }
    ans=max(ans,a[1]-a[0]);
    ans=max(ans,a[0]-a[1]);
    ans=max(ans,a[1]+a[0]);
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
using namespace std;
void solve(int n){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            a[i]=a[i]-a[i];
            a[i+1]=a[i+1]-a[i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main(){
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
    int n;
    cin>>n;
solve(n);
}

return 0;
}

Submission (verdict: Accepted):
#include<iostream>
using namespace std;
void solve(int n){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            a[i+1]=a[i+1]-a[i];
            a[i]=0;
        }
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main(){
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
    int n;
    cin>>n;
solve(n);
}

return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
using namespace std;
void solve(int n){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            a[i]=a[i]-a[i];
            a[i+1]=a[i+1]-a[i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main(){
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
    int n;
    cin>>n;
solve(n);
}

return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<iostream>
using namespace std;
void solve(int n){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            a[i]=a[i]-a[i];
            a[i+1]=a[i+1]-a[i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main(){
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
    int n;
    cin>>n;
solve(n);
}

return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
using namespace std;
void solve(int n){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            a[i]=a[i]-a[i];
            a[i+1]=a[i+1]-a[i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}
int main(){
int tc;
cin>>tc;
for(int i=0;i<tc;i++){
    int n;
    cin>>n;
solve(n);
}

return 0;
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;

    

    int state = 0;



    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;



    for (int i = x + 1, state = 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1, state = 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1, state = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    int state = 0;



    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;



    for (int i = x + 1, state = 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1, state = 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1, state = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;



    int state = 1;

    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    state = 1;

    for (int i = y + 1; i <= n; i ++)

        a[i] = (state ^= 1);

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    int state = 0;



    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;

    

    int state = 0;



    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    for (int i = y + 1; i <= n; i ++)

        a[i] = (state ^= 1);

    

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



    for (int i = 1; i <= n; i ++)

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

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


Submission (verdict: Time limit exceeded on test 15):
 
#pragma GCC optimize("O3,unroll-loops")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
 
typedef long long ll;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll combination(ll n, ll r, ll m, vector<ll>fact, vector<ll>ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
 
#define input(a, n) for(int i = 0; i < n; i++){cin>>a[i];}
#define print(a, n) for(int i = 0; i < n; i++) {cout<<a[i]<<' ';}
/*--------------------------------------------------------------------------------------------------------------------------*/
#define int ll
int solve(int i, int j, string a, string b, string c, vector<vector<int>>& dp){
    if(i + j >= c.size()) return 0;
    if(dp[i][j] != 0) return dp[i][j];

    int l = (i < a.size()) ? (((a[i] == c[i+j]) ? 0 : 1) + solve(i+1, j, a, b, c, dp)) : 1e9;
    int r = (j < b.size()) ? ((b[j] == c[i+j] ? 0 : 1) + solve(i, j+1, a, b, c, dp)) : 1e9; 

    dp[i][j] = min(l, r);

    return dp[i][j];
}

void solve(){
    int t;
    cin>>t;
    while(t--){
        string a, b, c;
        cin>>a>>b>>c;

        vector<vector<int>>dp(a.length()+1, vector<int>(b.length()+1, 0));

        int ans = solve(0, 0, a, b, c, dp);

        cout<<ans<<"\n";
    }
}
 
int32_t main(){
    fastio();
 
    solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

#include <vector>

#include <map>

using namespace std;

struct node

{

	int value=0;

	int location=0;

};

int main() {

	int n;

	cin >> n;

	map<int, int> m1, m2;

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

		//这个数在什么位置

		m1[n + 1 - i] = i;

		//存储的数

		m2[i] = n + 1 - i;

	}

	vector<int> brr(n + 1);

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

		cin >> brr[i];

	}

	int ans = n * (n - 1) / 2;

	vector<node> arr;

	for (int i = n; i > 0; i--) {

		ans += i - m1[brr[i]];

		for (int j = m1[brr[i]] + 1; j <= i; j++) {

			node temp;

			temp.value = brr[i];

			temp.location = m2[j];

			arr.push_back(temp);

		}

		int temp = m2[i];

		int temp2 = m1[brr[i]];

		m1[temp] = temp2;

		m1[brr[i]] = i;

		m2[i] = brr[i];

		m2[temp2] = temp;



	}

	cout << ans << endl;

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

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

			cout << j << " " << i << endl;

		}

	}

	for (int i = 0; i < arr.size(); i++) {

		cout << arr[i].location << " " << arr[i].value << endl;

	}

}

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

#include <vector>

#include <map>

using namespace std;

struct node

{

	int value=0;

	int location=0;

};

int main() {

	int n;

	cin >> n;

	map<int, int> m1, m2;

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

		//这个数在什么位置

		m1[n + 1 - i] = i;

		//存储的数

		m2[i] = n + 1 - i;

	}

	vector<int> brr(n + 1);

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

		cin >> brr[i];

	}

	int ans = n * (n - 1) / 2;

	vector<node> arr;

	for (int i = n; i > 0; i--) {

		ans += i - m1[brr[i]];

		for (int j = m1[brr[i]] + 1; j <= i; j++) {

			node temp;

			temp.value = brr[i];

			temp.location = m2[j];

			arr.push_back(temp);

			m1[brr[i]] = m1[brr[i]] + 1;

			m2[j] = brr[i];

			m1[temp.location] = m1[brr[i]] - 1;

			m2[j - 1] = temp.location;

		}



	}

	cout << ans << endl;

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

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

			cout << j << " " << i << endl;

		}

	}

	for (int i = 0; i < arr.size(); i++) {

		cout << arr[i].location << " " << arr[i].value << endl;

	}

}