ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long LL;

const int N = 100010;

int t , n;
int a[N];


int main()
{
    cin >> t;

    while( t -- )
    {
        cin >> n;

        LL ans = 0;
        for(int i = 0 ; i < n ; i ++ ) {cin >> a[i];ans += a[i];}

        
        while( n > 1)
        {   
            LL sum = 0;
            for(int i = 0;i < n - 1 ; i ++) 
            {
                a[i] = a[i + 1] - a[i];
                sum += a[i];
            }

            ans = max(ans, abs(sum));

            n --;
        }
        
        cout << ans << endl ;
        
    }

    return 0 ;
}

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

using namespace std;

typedef long long LL;

const int N = 100010;

LL t , n;
LL a[N];


int main()
{
    cin >> t;

    while( t -- )
    {
        cin >> n;

        LL ans = 0;
        for(LL i = 0 ; i < n ; i ++ ) {cin >> a[i];ans += a[i];}

        
        while( n > 1)
        {   
            LL sum = 0;
            for(LL i = 0;i < n - 1 ; i ++) 
            {
                a[i] = a[i + 1] - a[i];
                sum += a[i];
            }

            ans = max(ans, abs(sum));

            n --;
        }
        
        cout << ans << endl ;
        
    }

    return 0 ;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

using namespace std;

const int N = 100010;

int t , n;
int a[N];


int main()
{
    cin >> t;

    while( t -- )
    {
        cin >> n;

        int ans = 0;
        for(int i = 0 ; i < n ; i ++ ) {cin >> a[i];ans += a[i];}

        
        while( n > 1)
        {   
            int sum = 0;
            for(int i = 0;i < n - 1 ; i ++) 
            {
                a[i] = a[i + 1] - a[i];
                sum += a[i];
            }

            ans = max(ans, abs(sum));

            n --;
        }
        
        cout << ans << endl ;
        
    }

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


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



using namespace std;



const int N = 100010;



int t;

int a[N];



int main()

{

    cin >> t;



    while( t -- )

    {

        int n , l , r ;

        cin >> n >> l >> r;



        for(int i = 0 ;i < n ; i ++ ) cin >> a[i];



        //左

        int r1 = 0;

        int al[N] = {};



        for(int i = 0 ;i  < r ; i ++ ) al[i] = a[i];// 0 1 2 3 4 5

        sort(al , al + r - 1);

        for(int i = 0;i < r - l + 1 ;i ++ ) r1 += al[i];

    

        //右

        int r2 = 0;

        int cnt = 0;

        int ar[N] = {};



        for(int i = l - 1 ;i  < n ; i ++ ) ar[cnt ++ ] = a[i];

        sort(ar, ar + n - l + 1);

        for(int i = 0 ;i < r - l + 1 ; i ++ ) r2 += ar[i];



        cout << min(r1 , r2) << endl ;

    }



    return 0 ;

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

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



using namespace std;



const int N = 100010;



int t;

int a[N];



int main()

{

    cin >> t;



    while( t -- )

    {

        int n , l , r ;

        cin >> n >> l >> r;



        for(int i = 1 ;i <= n ; i ++ ) cin >> a[i];



        //左

        int r1 = 0;

        int al[N] = {};



        for(int i = 1 ;i  <= r ; i ++ ) al[i] = a[i];

        sort(al + 1 , al + r + 1);

        for(int i = 1;i <= r - l + 1 ;i ++ ) r1 += al[i];

    

        //右

        int r2 = 0;

        int cnt = 0;

        int ar[N] = {};



        for(int i = l ;i  <= n ; i ++ ) ar[ ++cnt ] = a[i];

        sort(ar + 1, ar + n - l + 2);

        for(int i = 1 ;i <= r - l + 1 ; i ++ ) r2 += ar[i];



        cout << min(r1 , r2) << endl ;

    }



    return 0 ;

}



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

using namespace std;

const int N = 100010;

int t;
int a[N];

int main()
{
    cin >> t;

    while( t -- )
    {
        int n , l , r ;
        cin >> n >> l >> r;

        for(int i = 1 ;i <= n ; i ++ ) cin >> a[i];

        //左
        long long r1 = 0;
        int al[N] = {};

        for(int i = 1 ;i  <= r ; i ++ ) al[i] = a[i];
        sort(al + 1 , al + r + 1);
        for(int i = 1;i <= r - l + 1 ;i ++ ) r1 += al[i];
    
        //右
        long long r2 = 0;
        int cnt = 0;
        int ar[N] = {};

        for(int i = l ;i  <= n ; i ++ ) ar[ ++cnt ] = a[i];
        sort(ar + 1, ar + n - l + 2);
        for(int i = 1 ;i <= r - l + 1 ; i ++ ) r2 += ar[i];

        cout << min(r1 , r2) << endl ;
    }

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

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



using namespace std;



const int N = 100010;



int t;

int a[N];



int main()

{

    cin >> t;



    while( t -- )

    {

        int n , l , r ;

        cin >> n >> l >> r;



        for(int i = 0 ;i < n ; i ++ ) cin >> a[i];



        //左

        int r1 = 0;

        int al[N] = {};



        for(int i = 0 ;i  < r ; i ++ ) al[i] = a[i];// 0 1 2 3 4 5

        sort(al , al + r - 1);

        for(int i = 0;i < r - l + 1 ;i ++ ) r1 += al[i];

    

        //右

        int r2 = 0;

        int cnt = 0;

        int ar[N] = {};



        for(int i = l - 1 ;i  < n ; i ++ ) ar[cnt ++ ] = a[i];

        sort(ar, ar + n - l + 1);

        for(int i = 0 ;i < r - l + 1 ; i ++ ) r2 += ar[i];



        cout << min(r1 , r2) << endl ;

    }



    return 0 ;

}

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



using namespace std;



const int N = 100010;



int t;

int a[N];



int main()

{

    cin >> t;



    while( t -- )

    {

        int n , l , r ;

        cin >> n >> l >> r;



        for(int i = 1 ;i <= n ; i ++ ) cin >> a[i];



        //左

        int r1 = 0;

        int al[N] = {};



        for(int i = 1 ;i  <= r ; i ++ ) al[i] = a[i];

        sort(al + 1 , al + r + 1);

        for(int i = 1;i <= r - l + 1 ;i ++ ) r1 += al[i];

    

        //右

        int r2 = 0;

        int cnt = 0;

        int ar[N] = {};



        for(int i = l ;i  <= n ; i ++ ) ar[ ++cnt ] = a[i];

        sort(ar + 1, ar + n - l + 2);

        for(int i = 1 ;i <= r - l + 1 ; i ++ ) r2 += ar[i];



        cout << min(r1 , r2) << endl ;

    }



    return 0 ;

}
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;

void solve(){
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }
    int maxi=accumulate(arr.begin(), arr.end(), 0);
    vector<int> newr=arr;
    while(newr.size()!=1){
        reverse(newr.begin(), newr.end());
        vector<int> temp(newr.size()-1);
        for(int i=0; i+1<newr.size(); i++){
            temp[i]=newr[i+1]-newr[i];
        }
        maxi=max(maxi, accumulate(temp.begin(), temp.end(), 0));
        newr=temp;
    }
    cout<<maxi<<endl;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

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

void solve(){
    long long int n;
    cin>>n;
    vector<long long int> arr(n);
    for(long long int i=0; i<n; i++){
        cin>>arr[i];
    }
    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }
    long long int maxi=accumulate(arr.begin(), arr.end(), 0LL);
    vector<long long int> newr=arr;
    while(newr.size()!=1){
        reverse(newr.begin(), newr.end());
        vector<long long int> temp(newr.size()-1);
        for(long long int i=0; i+1<newr.size(); i++){
            temp[i]=newr[i+1]-newr[i];
        }
        maxi=max(maxi, accumulate(temp.begin(), temp.end(), 0LL));
        newr=temp;
    }
    cout<<maxi<<endl;
}
int main() {
    long long int t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}
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;

void solve(){
    long long int n;
    cin>>n;
    vector<long long int> arr(n);
    for(long long int i=0; i<n; i++){
        cin>>arr[i];
    }
    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }
    long long int maxi=accumulate(arr.begin(), arr.end(), 0LL);
    vector<long long int> newr=arr;
    while(newr.size()!=1){
        reverse(newr.begin(), newr.end());
        vector<long long int> temp(newr.size()-1);
        for(long long int i=0; i+1<newr.size(); i++){
            temp[i]=newr[i+1]-newr[i];
        }
        maxi=max(maxi, accumulate(temp.begin(), temp.end(), 0LL));
        newr=temp;
    }
    cout<<maxi<<endl;
}
int main() {
    long long int t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

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

void solve(){
    long long int n;
    cin>>n;
    vector<long long int> arr(n);
    for(long long int i=0; i<n; i++){
        cin>>arr[i];
    }
    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }
    long long int maxi=accumulate(arr.begin(), arr.end(), 0LL);
    vector<long long int> newr=arr;
    while(newr.size()!=1){
        vector<long long int> temp(newr.size()-1);
        for(long long int i=0; i+1<newr.size(); i++){
            temp[i]=newr[i+1]-newr[i];
        }
        maxi=max(maxi, abs(accumulate(temp.begin(), temp.end(), 0LL)));
        newr=temp;
    }
    cout<<maxi<<endl;
}
int main() {
    long long int t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


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

void solve(){
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }
    int maxi=accumulate(arr.begin(), arr.end(), 0);
    vector<int> newr=arr;
    while(newr.size()!=1){
        reverse(newr.begin(), newr.end());
        vector<int> temp(newr.size()-1);
        for(int i=0; i+1<newr.size(); i++){
            temp[i]=newr[i+1]-newr[i];
        }
        maxi=max(maxi, accumulate(temp.begin(), temp.end(), 0));
        newr=temp;
    }
    cout<<maxi<<endl;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int count=0;
        for(int i=0;i<a.size();i++){
            k-=a[i];
            count++;
            if(k<0) break;
        }
        cout << a.size()-count+1 << endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int flag=0;
        for(int i=0;i<a.size()-1;i++){
            if(k<a[i]){
                cout << a.size()-i << endl;
                flag=1;
                break;
            }
            k-=a[i];
        }
        if(!flag)cout << 1 << endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int flag=0;
        for(int i=0;i<a.size()-1;i++){
            if(k<a[i]){
                cout << a.size()-i << endl;
                flag=1;
                break;
            }
            k-=a[i];
        }
        if(!flag)cout << 1 << endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int count=0;
        for(int i=0;i<a.size();i++){
            k-=a[i];
            count++;
            if(k<0) break;
        }
        cout << a.size()-count+1 << endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int flag=0;
        for(int i=0;i<a.size()-1;i++){
            if(k<a[i]){
                cout << a.size()-i << endl;
                flag=1;
                break;
            }
            k-=a[i];
        }
        if(!flag)cout << 1 << endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        int k;cin >> k;
        vector<int> v(n);
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            cin >> v[i];
            m[v[i]]++;
        }
        vector<int> a;
        for(auto m:m){
            a.push_back(m.second);
        }
        sort(a.begin(),a.end());
        int flag=0;
        for(int i=0;i<a.size()-1;i++){
            if(k<a[i]){
                cout << a.size()-i << endl;
                flag=1;
                break;
            }
            k-=a[i];
        }
        if(!flag)cout << 1 << endl;
    }
    return 0;
}

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

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    vector<int> cnt = {1};
    for (int i = 1; i < n; i++) {
        if (v[i] == v[i - 1]) {
            cnt.back()++;
        } else {
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    cout << 1 << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin()+1,a.end());
    vector<pair<ll,ll>>q;
    map<ll,map<ll,ll>>vis;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i;j++){
            if(a[j].second>a[j+1].second){
                q.push_back({a[j+1].first,a[j].first});
                vis[a[j+1].first][a[j].first]=1;
                swap(a[j+1],a[j]);
            }
        }
    }
    for(int i=1;i<n;i++){
        ll t=i;
        while(t<n&&!vis[a[t].first][a[t+1].first]&&!vis[a[t+1].first][a[t].first])t++;
        if(t<=i)continue;
        for(int j=1;j<=t-i+1;j++){
            for(int l=t;l>i;l--){
                q.push_back({a[l].first,a[l-1].first});
                swap(a[l],a[l-1]);
            }
        }
        i=t;
    }
    cout<<q.size()<<"\n";
    for(auto i:q){
        cout<<i.first<<" "<<i.second<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    map<ll,map<ll,ll>>vis;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(a[i]>a[j])vis[a[i]][a[j]]++;
            else vis[a[i]][a[j]]++,vis[a[j]][a[i]]++;
        }
    }
    vector<pair<ll,ll>>ans;
    sort(a.begin()+1,a.end());
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(vis[a[j+1]][a[j]]){
                vis[a[j+1]][a[j]]--;
                ans.push_back({a[j+1],a[j]});
                swap(a[j+1],a[j]);
            }
        }
    }
    cout<<ans.size()<<"\n";
    for(auto i:ans){
        cout<<i.first<<" "<<i.second<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    solve();
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin()+1,a.end());
    vector<pair<ll,ll>>q;
    map<ll,map<ll,ll>>vis;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i;j++){
            if(a[j].second>a[j+1].second){
                q.push_back({a[j+1].first,a[j].first});
                vis[a[j+1].first][a[j].first]=1;
                swap(a[j+1],a[j]);
            }
        }
    }
    for(int i=1;i<n;i++){
        if(vis[a[i].first][a[i+1].first]||vis[a[i+1].first][a[i].first])continue;
        vis[a[i].first][a[i+1].first]=vis[a[i+1].first][a[i].first]=1;
        q.push_back({a[i+1].first,a[i].first});
        q.push_back({a[i].first,a[i+1].first});
    }
    cout<<q.size()<<"\n";
    for(auto i:q){
        cout<<i.first<<" "<<i.second<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    solve();
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin()+1,a.end());
    vector<pair<ll,ll>>q;
    map<ll,map<ll,ll>>vis;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i;j++){
            if(a[j].second>a[j+1].second){
                q.push_back({a[j+1].first,a[j].first});
                vis[a[j+1].first][a[j].first]=1;
                swap(a[j+1],a[j]);
            }
        }
    }
    for(int i=1;i<n;i++){
        if(vis[a[i].first][a[i+1].first]||vis[a[i+1].first][a[i].first])continue;
        vis[a[i].first][a[i+1].first]=vis[a[i+1].first][a[i].first]=1;
        q.push_back({a[i+1].first,a[i].first});
        q.push_back({a[i].first,a[i+1].first});
    }
    cout<<q.size()<<"\n";
    for(auto i:q){
        cout<<i.first<<" "<<i.second<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    solve();
}


Submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin()+1,a.end());
    vector<pair<ll,ll>>q;
    map<ll,map<ll,ll>>vis;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i;j++){
            if(a[j].second>a[j+1].second){
                q.push_back({a[j+1].first,a[j].first});
                vis[a[j+1].first][a[j].first]=1;
                swap(a[j+1],a[j]);
            }
        }
    }
    for(int i=1;i<n;i++){
        ll t=i;
        while(t<n&&!vis[a[t].first][a[t+1].first]&&!vis[a[t+1].first][a[t].first])t++;
        if(t<=i)continue;
        for(int j=1;j<=t-i+1;j++){
            for(int l=t;l>i;l--){
                q.push_back({a[l].first,a[l-1].first});
                swap(a[l],a[l-1]);
            }
        }
        i=t;
    }
    cout<<q.size()<<"\n";
    for(auto i:q){
        cout<<i.first<<" "<<i.second<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    solve();
}
Problem: 2062C - Cirno and Operations
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;
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();
}