ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void solve() {
    string input;
    cin >> input;

    vector<int> s;
    for (char c : input) {
        s.push_back(c - '0'); // Convert char to int and store in vector
    }

    int sm = 0;
    int twos = 0, threes = 0;

    for (int digit : s) {
        sm += digit;
        if (digit == 2) twos++;
        if (digit == 3) threes++;
    }

    for (int i = 0; i <= min(10, twos); i++) {
        for (int j = 0; j <= min(10, threes); j++) {
            if ((sm + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}

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


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;

        ll twos = 0;
        ll threes = 0;
        ll sum = 0;
        string res = "no";
        for (auto c : n) {
            int temp = c - '0';
            sum += temp;
            if (temp == 2) {
                ++twos;
            } else if (temp == 3) {
                ++threes;
            }
        }
        twos = min((ll)9, twos);
        threes = min((ll)3, threes);
        int curr_sum = sum % 9;
        
        vector<bool> possible (9, false);
        
        possible[curr_sum] = true;
        
        for (int i = 0; i < twos; ++i) {
            curr_sum = (curr_sum + 2) % 9;
            possible[curr_sum] = true;
        }
        for (int i = 0; i < threes; ++i) {
            for (int j = 0; j < 9; ++j) {
                if (possible[j]) {
                    possible[(j + 6) % 9] = true;
                }
            }
        }
        
        if (possible[0]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 233 ms):
#include<bits/stdc++.h>
using namespace std;

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

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

        // vector<int> v(n);

        map<int,int> mp;
        int x;
        for(int i=0;i<n;i++){
            cin>>x;
            mp[x]++;
        }

        vector<int> freq;

        for(auto p:mp){
            freq.push_back(p.second);
        }

        sort(freq.begin(),freq.end());

        int ans = 1;

        int i=0;
        for(int i=0;i<freq.size()-1;i++){
            if(k>=freq[i]){
                k-=freq[i];
            }else{
                ans++;
            }
        }
        
        cout<<ans<<endl;
        
    }
}

Solution 2 (runtime: 108 ms):
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>

using namespace std;

#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define uset unordered_set
#define umap unordered_map

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

#define debugp(p) cout << "f=" << p.first << ",s=" << p.second << "\n"
#define debugiter(c) for (const auto& v : c) std::cout << v << " "

void solve() {
    int N, K; cin >> N >> K;
    map<int, int> nums;
    for (int i = 0; i < N; i++) {
        int num; cin >> num;
        nums[num]++;
    }

    if (K == N) {
        cout << "1\n";
        return;
    }

    priority_queue<int, vi, greater<int>> smallestFreqs;
    for (const auto& pair : nums)
        smallestFreqs.push(pair.second);

    int numChanged = 0;
    while (true) {
        int leastFreq = smallestFreqs.top();
        if (leastFreq > K)
            break;

        K -= leastFreq;
        numChanged++;
        smallestFreqs.pop();
    }

    cout << (nums.size() - numChanged) << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T; cin >> T;
    while (T--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;

int solve(string &a, string &b, string &c) {
    int n = a.size(), m = b.size(), l = c.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));

    dp[0][0] = 0; // Base case: Matching empty prefixes costs 0.

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            int k = i + j; // Current index in `c`.
            if (k > l) continue;

            if (i < n && c[k] == a[i]) { 
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            } else if (i < n) { 
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
            }

            if (j < m && c[k] == b[j]) { 
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
            } else if (j < m) { 
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
            }
        }
    }

    return dp[n][m];
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;

    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        cout << solve(a, b, c) << endl;
    }

    return 0;
}


Solution 2 (runtime: 78 ms):
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

int f(string &a,string &b,string &c,int x,int y,int z,vector<vector<int>> &dp){
    if(z<0) return 0;
    if(x<0 && y<0 ){
        return INT_MAX;
    }
    if(dp[x+1][y+1]!=-1){
        return dp[x+1][y+1];
    }
    int a_take=INT_MAX;
    int b_take=INT_MAX;
    if(x>=0) a_take=(c[z]!=a[x])+f(a,b,c,x-1,y,z-1,dp);
    if(y>=0) b_take=(c[z]!=b[y])+f(a,b,c,x,y-1,z-1,dp);
    return dp[x+1][y+1]=min(a_take,b_take);
}

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

    int t;
    cin>>t;

    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int x=a.size();
        int y=b.size();
        int z=c.size();
        vector<vector<int>> dp(x + 1, vector<int>(y + 1, -1));
        int result = f(a,b,c,x-1,y-1,z-1,dp);
        if (result >= INT_MAX) result=-1; 
        cout << result << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l - 1; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Solution 2 (runtime: 202 ms):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

/* int best = 0, sum = 0;

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

sum = max(array[k],sum+array[k]);

best = max(best,sum);

}

cout << best << "\n";*/

long long binpow(long long a, long long b) {

    if (b == 0)

        return 1;

    long long res = binpow(a, b / 2);

    if (b % 2)

        return res * res * a;

    else

        return res * res;

}

int main(){

    int t;

    cin>>t;

    while(t--) {

        int n,l,r;

        cin>>n>>l>>r;

        vector<ll> v,v1;

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

            int x;

            cin>>x;

            if(i<=r) {

                v.push_back(x);

            }

            if(i>=l) {

                v1.push_back(x);

            }

        }

        sort(v1.begin(),v1.end());

        sort(v.begin(),v.end());

        ll sum1=0,sum2=0;

        for(int i=0;i<=r-l;i++) {

            sum1+=v[i];

        }

        for(int i=0;i<=r-l;i++) {

            sum2+=v1[i];

        }

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

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
int main () {
	int t; cin >> t;
	while (t--) {
		string s;
		cin >> s;
		int n = s.size();
		int a[n];
		for (int i = 0; i < n; i++) {
			a[i] = s[i] - '0' - i;
		}
		for (int i = 0; i < n; i++) {
			int m = a[i], im = i;
			for (int j = i; j < n and j < i + 10; j++) {
				if (a[j] > m) {
					im = j, m = a[j];
				}
			}
			int t, t1 = m + 1;
			for (int j = i; j <= im; j++) {
				t = a[j];
				a[j] = t1 - 1;
				t1 = t;
			}
		}
		for (int i = 0; i < n; i++) 
			cout << a[i] + i;
		cout << endl;
	}
	return 0;
}


Solution 2 (runtime: 171 ms):
#include <bits/stdc++.h>

using namespace std;



bool solve(string &s,int index){

    

    for(int i=max(index,0);i<s.size()-1;i++){

        if((s[i]-'0') < (s[i+1]-'0')-1){

            s[i+1] = (s[i+1]-'0'-1) + '0';

            swap(s[i],s[i+1]);

            if(solve(s,i-1)==true)return true;

        }

    }

    

    return true;

}



int main() {

	// your code goes here

	int t;

	cin>>t;

	while(t--){

	    string s;

	    cin>>s;

	    solve(s,0);

	    

	    for(auto &i : s){

	        cout<<i;

	    }

	    cout<<endl;

	   

	}



}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include "algorithm"

using namespace std;

#define int long long


void solve() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] > a[i]) {
            cout << "nO\n";
            return;
        }
        int t = min(a[i], a[i - 1]);
        a[i - 1] -= t;
        a[i] -= t;
    }
    cout << "YeS\n";
}




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

Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

cout.tie(NULL);

int t;

cin >> t;

while (t--)

{

int n;

cin >> n;

int a[n];

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

cin >> a[i];

int h=1;

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

{

if(a[i]>a[i+1])

{

h=0;

break;

}

int p=min(a[i],a[i+1]);

a[i]-=p;

a[i+1]-=p;

}

if(h==1)

cout<<"YES"<<endl;

else

cout<<"NO"<<endl;

}

return 0;

}



//

// Created by gjs27 on 25-3-31.

//
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 296 ms):
#include <iostream>
using namespace std;

    int t,n,m,av;
	long long int sum;
    int arr[200100];
int main(){
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>n;
        
        sum=0;
        for(int j=0;j<n;j++){
            cin>>arr[j];
            sum+=arr[j];
        }
        av=sum/n;
        if(float(av)!=(float)((float)sum/(float) n)){
            cout<<"NO"<<endl;
            continue;
        }
        for(int j=1;j<n-1;j++){
            m=arr[j-1]-av;
            arr[j-1]=av;
            arr[j+1]+=m;
        }
        if(arr[n-1]==av&&arr[n-2]==av){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }


        
    }
}

Solution 2 (runtime: 343 ms):
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n; cin >> n;
    long long sum = 0;
    vector<int> arr;
    for(int i=0; i<n; i++) {
        long long x; cin >> x;
        arr.push_back(x);
        sum += x;
    }
    if(sum%n==0) {
        long long num = sum/n;
        long long a = 0, b = 0;
        long long cA = 0, cB = 0;
        for(int i=0; i<n; i+=2){ 
            cA ++;
            a += arr[i];
        }
        for(int i=1; i<n; i+=2){ 
            cB ++;
            b += arr[i];
        }
        if(a/cA == num && b/cB == num) cout << "YES\n";
        else cout << "NO\n";
    }
    else cout << "NO\n";
}

int main () {

    int t; cin >> t;
    while(t--) {
        solve();
    }

    return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"\n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

Solution 2 (runtime: 31 ms):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define int long long

const ll N=1e9+7;



void solve(){

    int n;

    cin>>n;

    string s;

    cin>>s;

    if(s[0]=='s') s[0]='.';

    if(s[n-1]=='p') s[n-1]='.';

    int cs=count(s.begin(),s.end(),'s');

    int cp=count(s.begin(),s.end(),'p');

    int cd=count(s.begin(),s.end(),'.');

    if(cs==0||cp==0) {cout<<"YES\n"; return;}

    cout<<"NO\n";

    return;

}



int32_t main() {

    ios::sync_with_stdio(0); 

    cin.tie(0);

    ll t;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
    #define debug(x) cerr<<#x<<": "<<x<<endl;
#else
    #define debug(x)
    #define cerr if (false) cerr
#endif

#define endl "\n"       //remove this for interactive problems
#define space " "
#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> void printit(vector<T> v, int x=1) {if(x==2) return; for (T i : v) if (x==1) cout<<i<<" "; else cerr<<i<<" "; if (x==1) cout<<endl; else cerr<<endl;}

//---------------------------------------------------------------------------------------------------//

/*
auto check = [&](int mid) -> bool{
        //conditions
        return true;
    };
*/
int MOD = 1e9 + 7;
// (a += (b*c)%MOD ) %= MOD ;

void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    
    l--;
    r--;

    vector<int> arr(n, 0);
    vector<int> segment, left, right;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if (i<l)
        {
            left.push_back(arr[i]);
        }
        else if (i>=l && i<=r)
        {
            segment.push_back(arr[i]);
        } else
        {
            right.push_back(arr[i]);
        }
    }

    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    sort(segment.begin(), segment.end());

    int sum = accumulate(segment.begin(), segment.end(), 0LL);

    int answer = sum;
    
    int i=0, j=segment.size();
    j--;
    while (j>=0 && i<left.size())
    {
        sum = sum - segment[j];
        sum += left[i];
        j--;
        i++;

        answer = min(answer, sum);
    }
    sum = accumulate(segment.begin(), segment.end(), 0LL);

    i = 0, j = segment.size();
    j--;
    while (j >= 0 && i < right.size())
    {
        sum = sum - segment[j];
        sum += right[i];
        j--;
        i++;

        answer = min(answer, sum);
    }

    cout<<answer<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;cin >> t;while (t--) 
    solve();

    
    return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
#include <string>

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define ll long long int
#define int long long 
#define endl "\n"
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back

using namespace std;

void solve()
{
    int n, l, r;
    cin >> n >> l >> r;
    
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }

    vector<int> b = a;
    sort(b.begin()+l-1, b.end());

    vector<int> c = a;
    sort(c.begin(), c.begin()+r, greater<int>());

    int sb = 0, sc = 0;
    for (int i=l-1; i<r; i++) {
        sb += b[i];
        sc += c[i];
    } 

    cout << min(sb, sc) << endl;
}

int32_t main()
{
    FAST_IO;
    int t;
    cin >> t;

    while (t--)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
#define ll long long int 
#define INF (ll)1e18
#define mod 998244353
using namespace std;
ll pow_mod(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2)
        res=(res*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return res;
}
int main(){
    ll t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        for(int i = 0 ; i < n ; i++){
            // if((s[i]-'0') == 0) {
            //     continue;
            // }
            int maxi = s[i]-'0';
            int maxi_idx = i;
            int cnt = 0;
            bool chk = false;
            for(int j = i+1 ; j < min(i+9,n) ; j++){
                cnt++;
                if(maxi < ((s[j]-'0')-cnt)){
                    chk = true;
                    maxi = (s[j]-'0')-cnt;
                    maxi_idx = j;
                    //cout<<maxi<<"  "<<maxi_idx<<endl;
                }
            }
            if(chk){
                //cout<<maxi<<"  "<<maxi_idx<<"  "<<cnt<<endl;
                char val = '0'+maxi;
                //cout<<val<<endl;
                for(int j = maxi_idx ; j >= i ; j--){
                    if(j-1 >= 0) s[j] = s[j-1];
                }
                s[i] = val;
            }
            //cout<<s<<endl;
        }
        cout<<s<<endl;
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;



void maximizeString(string &s) {

    int n = s.size();

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

        // Check if the current digit can be decreased and swapped

        if (s[i] != '0' && (s[i] - s[i - 1]) >= 2) {

            // Decrease the current digit by 1

            s[i]--;

            // Swap it with the previous digit

            swap(s[i], s[i - 1]);

            // Move back one step to recheck the previous pair

            i -= 2;

            if (i < 0) i = 0; // Ensure i doesn't go below 0

        }

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        maximizeString(s);

        cout << s << endl;

    }

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1515 ms):
#include <bits/stdc++.h>

long long mod = 1000000007;

long long inf = 200009;

#define ll long long

#define ull unsigned long long

#define fl(i, m, n) for (ll i = m; i < n; i++)

#define flr(i, m, n) for (ll i = m; i > n; i--)



using namespace std;



int n;

vector<int> c;



void solve()

{

    vector<int> pos(n + 1);

    fl(i, 0, n) pos[c[i]] = i;

    set<pair<int, int>> swaps;

    ll ans = 0;

    fl(i, 1, n + 1)

    {

        fl(j, i + 1, n + 1)

        {

            if (pos[i] > pos[j])

            {

                ans += 1;

            }

            else

            {

                ans += 2;

                swaps.insert({i, j});

            }

        }

    }

    cout << ans << endl;

    fl(i, 1, n + 1)

    {

        fl(j, i + 1, n + 1)

        {

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

        }

    }

    vector<int> cur(n + 1);

    fl(i, 1, n + 1) cur[i] = n + 1 - i;

    while (swaps.size() > 0)

    {

        fl(i, 1, n)

        {

            if (swaps.count({cur[i], cur[i + 1]}) > 0)

            {

                swap(cur[i], cur[i + 1]);

                cout << cur[i + 1] << " " << cur[i] << endl;

                swaps.erase({cur[i + 1], cur[i]});

            }

            if (swaps.count({cur[i + 1], cur[i]}) > 0)

            {

                swap(cur[i + 1], cur[i]);

                cout << cur[i] << " " << cur[i + 1] << endl;

                swaps.erase({cur[i], cur[i + 1]});

            }

        }

    }

}



int main()

{

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    cin >> n;

    c.resize(n);

    fl(i, 0, n) cin >> c[i];

    solve();



    return 0;

}



Solution 2 (runtime: 296 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define I inline
#define reg register
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define i128 __int128
#define uint unsigned int
constexpr int N=1100;
int n,c[N],p[N],vis[N][N];
stack<pii>st;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=n;i++)p[c[i]]=i;
  for(int i=n;i;i--){
    int j=0;
    for(j=p[i]-1;j&&c[j]<c[j+1];j--)
      vis[c[j+1]][c[j]]=1,vis[c[j]][c[j+1]]=1,
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<p[i];j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=p[i]+1;j<=i;j++)
      vis[c[j-1]][c[j]]=1,vis[c[j]][c[j-1]]=1,p[c[j]]=j-1,
      st.push(mp(c[j-1],c[j])),swap(c[j-1],c[j]);
    // for(int j=1;j<=n;j++)cout<<c[j]<<' ';cout<<'\n';
  }
  for(int i=n;i;i--){
    int j=0;
    for(j=i-1;j&&!vis[c[j]][c[j+1]];j--)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<i;j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
  }
  cout<<st.size()<<'\n';
  while(!st.empty()){
    pii u=st.top();
    cout<<u.fi<<' '<<u.se<<'\n';
    st.pop();
  }
  return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;

int main()
{
  long long  t;
  cin >> t;
  while (t--)
  {
    long long  n;
    cin>>n;
    vector<long long >v(n);
     for(int i=0;i<n;i++)
    {
      cin>>v[i];
    }
    long long  now = n;
    long long ans = -1e18;
    for(int i=0;i<n;i++)
    {
      long long sum =0;
      
      for(int j=0;j<now;j++)
      {
        sum +=v[j];
      }
      if(i==0)
      {
        ans = max(ans,sum);
      }
      else
      {
        ans = max(ans,max(sum,(-sum)));
      }
      for(int k=0;k<now-1;k++)
      {
        v[k] = v[k+1]-v[k];
      }
      now--;
    }
    cout<<ans<<endl;
  }
}


Solution 2 (runtime: 61 ms):
#include <iostream>
using namespace std;
using ll = long long;

int main(){
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n;
        ll ans=0;
        ll arr[51];
        for(ll i=1;i<=n;++i){
            cin >> arr[i];
            ans+=arr[i];
        }
        while(n>1){
            ans=max(ans,abs(arr[n]-arr[1]));
            for(ll i=1;i<n;i++){
                arr[i]=arr[i+1]-arr[i];
            }
            --n;
        }
        cout << ans << endl;
    }
}