ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 202 ms):
#include "bits/stdc++.h"
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;


void solve(){
    int n, m; cin >> n >> m;
    priority_queue<int> pq_a, pq_b;
    int val;
    for (int i=0; i<n; ++i) {
        cin >> val;
        pq_a.push(val);
    }
    for (int i=0; i<m; ++i) {
        cin >> val;
        pq_b.push(val);
    }
    while (!pq_a.empty() && !pq_b.empty()) {
        int val_a = pq_a.top();
        int val_b = pq_b.top();
        pq_a.pop();
        pq_b.pop();
        if (val_a == val_b) continue;
        if (pq_a.size() < pq_b.size()) {
            cout << "NO\n";
            return;
        }
        pq_a.push(val_a);
        pq_b.push(val_b/2);
        pq_b.push((val_b + 1) / 2);
    }
    if (pq_a.empty() && pq_b.empty()) cout << "YES\n";
    else cout << "NO\n";
}


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

Solution 2 (runtime: 671 ms):
#include <iostream>  

#include <vector>  

#include <algorithm>  

#include <string>  

#include <cmath> 

#include <queue>  

#include <deque>

#include <stack>  

#include <utility>  

#include <map>  

#include <set>  

#include <unordered_map>  

#include <unordered_set>  

#include <chrono>

#include <pthread.h>



#define ll long long int

#define pb push_back

#define mp make_pair

#define mod 998244353

#define pi 3.141592653589793

#define N 100001



using namespace std;





void f() {

    int n, m;

    cin >> n >> m;

    unordered_map<int, int> d;

    priority_queue<int> a, b;

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

        int e;

        cin >> e;

        a.push(e);

    }

    for (int i = 0; i < m; i++) {

        int e;

        cin >> e;

        b.push(e);

    }



    while (!b.empty() && b.size() <= a.size() && b.top() >= a.top()) {

        int first = b.top();

        if (first == a.top()) {

            a.pop();

            b.pop();

        }

        else {

            b.pop();

            b.push(first - first / 2);

            b.push(first / 2);

        }

    }



    if (a.empty() && b.empty()) cout << "Yes\n";

    else cout << "No\n";





}



int main() {

    int t;

    cin >> t;

    while (t--) {

        f();



    }

    return 0;

}







// 5

// 12 1 2

// 12 1 1

// 12 0 0

// 12 1000000000 1000000000

// 706636307 0 3
Problem: 2049C - MEX Cycle
Language: c++17 

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace std;

using namespace __gnu_pbds;

 

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

typedef long long ll;

using ull = uint64_t;

 

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

int rnd(int x, int y) {

  return uniform_int_distribution<int>(x, y)(rng);

}

//START-----------------------------------

 

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;

        int diff = y - x;

        vector<int>ans(n+5);

        if(n&1)

        {

                ans[x] = 2;

                int f = 0;

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

                {

                    ans[i] = f;

                    f ^= 1;

                }

                f = 1;

                for(int i=x-1; i>=1; i--)

                {

                    ans[i] = f;

                    f ^= 1;

                }

        }

        else

        {

            int  f = 0;

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

            {

                ans[i] = f;

                f ^= 1;

            }

            

            if(ans[x] == ans[y])

                ans[x] = 2;

        }



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

            cout<<ans[i]<<' ';

        cout<<'\n';

    }

 

    return 0;

}

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

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

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

#define pb push_back

void solve(){

	int n , x , y; cin >> n >> x >> y;

	x = (x + n - 1) % n; y = (y - 1 + n) % n;

	vector<int> a(n);

	int pos = 10;

	while(pos --){

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		for(int j = 0;j <= 100; ++ j){

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

		

	} 

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

		set<int> s;

		if(i == x) s.insert(a[y]);

		if(i == y) s.insert(a[x]);

		s.insert(a[(i - 1 + n) % n]);

		s.insert(a[(i + 1) % n]);

		for(int j = 0;j <= 100; ++ j){

			if(s.find(j) == s.end()) {

				a[i] = j;

				break;

			}

		}

	} 

	}

	 for(auto v : a) cout << v << ' ';

	cout << endl;

	return;

}

int main(){

	std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr);

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/
Problem: 2050E - Three Strings
Language: c++17 

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

ll solve(ll i,ll j,vector<vector<ll>>&dp,string a,string b,string c,ll n1,ll n2){
     if(i==a.size()&&j==b.size())return 0;
     if(dp[i][j]!=-1){
        return dp[i][j];
     }
     ll res=LLONG_MAX;
   
      if(i<a.size()&&a[i]==c[i+j]){
          res=solve(i+1,j,dp,a,b,c,n1,n2);
     }
     if(j<b.size()&&b[j]==c[i+j]){
        res=min(res,solve(i,j+1,dp,a,b,c,n1,n2));
     }
     
       
        if(i<a.size())
        res=min(res,1+solve(i+1,j,dp,a,b,c,n1,n2));
        if(j<b.size())
        res=min(res,1+solve(i,j+1,dp,a,b,c,n1,n2));
     

     return dp[i][j]=res;
}

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

    while (t--) {
       
     string a;
     string b;
     string c;

     cin>>a;
     cin>>b;
     cin>>c;
     ll n=a.size()+b.size();
     ll n1=a.size();
     ll n2=b.size();
     vector<vector<ll>>dp(n1+1,vector<ll>(n2+1,LLONG_MAX));
     dp[n1][n2]=0;
     
     for(ll i=n1;i>=0;i--){
        for(ll j=n2;j>=0;j--){
              if(i==n1&&j==n2) continue;
     
    
   
      if(i<a.size()&&a[i]==c[i+j]){
          dp[i][j]=min(dp[i][j],dp[i+1][j]);
     }
     if(j<b.size()&&b[j]==c[i+j]){
        dp[i][j]=min(dp[i][j],dp[i][j+1]);
     }
     
       
        if(i<a.size())
        dp[i][j]=min(dp[i][j],1+dp[i+1][j]);
        if(j<b.size())
        dp[i][j]=min(dp[i][j],1+dp[i][j+1]);
     

     dp[i][j]=dp[i][j];
        }
     }
     cout<<dp[0][0]<<endl;
    

       
    }

    return 0;
}


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

#define ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector < ll > vl; 
typedef set < ll > setl;
#define ff first
#define ss second    
#define all(v) v.begin(), v.end() 
#define pll pair<ll, ll> 
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const ll mod =  1000007;
const int MAX = 1e3 + 5;
const int imax = 2147483647;
ll n, m, k, res;
string a, b, c;
void solve(){
    cin >> a >> b >> c;
    n = a.size();
    m = b.size();
    a = '0' + a;
    b = '0' + b;
    c = '0' + c;
    vector < vl > dp(n + 5, vl (m + 5, INT_MAX));
    dp[0][0] = 0;
    FORI(i, n + 1){
        FORI(j, m + 1){
            if(!i && !j)continue;
            if(!i){
                dp[i][j] = dp[i][j - 1] + 1;
            }
            else if(!j)dp[i][j] = dp[i - 1][j] + 1;
            else dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
            if(i && c[i + j] == a[i]){
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            }
            if(j && c[i + j] == b[j]){
                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    cout << dp[n][m];
}
signed main(){      
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    sync;
    ll t = 1;
    cin >> t;
    FOR(i, t){
        // cout << "Case #" << i << ": ";
        solve();
        nll;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
    int t;
    cin >> t;
    while(t--) {
        LL l, r;
        cin >> l >> r;
        int k = (int)log2(l ^ r);
        int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
        std::cout << a << " " << b << " " << c << "\n";
    } 
    return 0;
}

Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

void solved()
{
    int l,r;
    cin>>l>>r;
    int k = (l^r);
    bitset<31>b(k);
    int ans = 0;
    for(int i = 0;i<=30;i++)
    {
        if(b[i] == 1)
        {
            ans = i;
        }
    }
    int result = l | ((1 << ans) - 1 );
    cout<<result<<" ";
    cout<<result + 1<<" ";
    cout<<(result == l ? r : l )<<endl;
}



signed main()
{
    close;
    int T;
    cin>>T;
    while(T--)
    {
        solved();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

void solve()
{
    ll l,r;
    cin>>l>>r;

    ll ans=0, a, b, c;
    for (ll i=30; i>=0; i--){
        ll b1=0, b2=0;

        if (l & (1ll<<i)){
            b1=1;
        }

        if (r & (1ll<<i)){
            b2=1;
        }

        if (b1==b2){
            ans+=b1*(1ll<<i);
        }
        
        else{
            a=ans+(1ll<<i);
            b=a-1;
            break;
        }
    }

    for (ll i=l; i<=r; i++){
        if (i!=a && i!=b){
            c=i;
            break;
        }
    }

    cout<<a<<" "<<b<<" "<<c<<endl;
    return;
}

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

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

Solution 2 (runtime: 62 ms):
﻿#define  _CRT_SECURE_NO_WARNINGS 1

#include <math.h>
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <bitset>

using namespace std;

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 2e9
#define maxn 100005
#define eps 1e-8
const int mod = 998244353;

#define Neg -2147483647
#define Pos 2147483647

#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define el '\n'

int l, r;

void ans(int a, int b, int c) {
	cout << (a ^ b) + (b ^ c) + (c ^ a) << el;
}

int len(int x) {
	int p = 0;
	while ((x >> 1) >= (1 << p))
		p++;
	return p;
}

int neg(int x) {
	for (int i = len(x); i >= 0; i--) {
		if (((x>>i)&1) == 1) x -= (1 << i);
		else x += (1 << i);
	}
	return x;
}

bool check(int x)
{
	return x <= r && x >= l;
}

void solve()
{

	cin >> l >> r;
	if (r - l == 2) {
		cout << l << " " << r - 1 << " " << r << el;
		return;
	}


	int a, b, c;
	int beg = (l >> len(l ^ r)) << len(l ^ r);
	a = beg + (1 << len(l ^ r));
	b = a - 1;
	c = check(a + 1) ? a + 1 : b - 1;
	
	cout << a << " " << b << " " << c << el;
}

int main()
{

	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int _ = 1;
	cin >> _;
	for (int i = 0; i < _; i++)
	{
		solve();
	}

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

Solution 1 (runtime: 93 ms):
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long LL;

const int N = 300010;

int a[N];

int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        int n, l, r;
        scanf("%d%d%d", &n, &l, &r);
        for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
        
        vector<int> v;
        for (int i = 1; i <= r; i ++) v.push_back(a[i]);
        sort(v.begin(), v.end());
        
        LL x = 0, y = 0;
        for (int i = 0; i < r - l + 1; i ++) x += v[i];
        v.clear();
        for (int i = l; i <= n; i ++) v.push_back(a[i]);
        sort(v.begin(), v.end());
        for (int i = 0; i < r - l + 1; i ++) y += v[i];
        
        printf("%lld\n", min(x, y));
    }
	return 0;
} 

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

using namespace std;





void solve() {

    int n, l, r;

    cin >> n >> l >> r;



    l--;

    r--;

    vector<long long> a(n);

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

    int size = r - l + 1;

    vector<long long> first(a.begin(), a.begin() + r + 1);

    vector<long long> second(a.begin() + l, a.end());



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



    long long res =  LONG_LONG_MAX;

    long long sum = 0;

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

        sum += first[i];

    }



    res = min(sum, res);



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

    sum = 0;



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

        sum += second[i];

    }



    res = min(sum, res);



    cout << res << endl;

}



int main() {

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



    int t;

    cin >> t;

    while (t--) {

        solve();

    }

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

Solution 1 (runtime: 359 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        vll a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        if (a[0] > a[1] )
        {
            cout << "NO" << endl;
        }
        else
        {
            bool lucky = true;
            for (int i = 0; i < n - 1; i++)
            {
                
                
                if (a[i + 1] < a[i])
                {
                    lucky = false;
                    break;
                }
                a[i + 1] = a[i + 1] - a[i];
                a[i]=0;
                // cout<<a[i]<<" ";
            }
            //  cout<<a[n-1]<<endl;
            if (!lucky)
            {
                cout << "NO" << endl;
            }
            else
            {
                cout << "YES" << endl;
            }
        }
    }
}

Solution 2 (runtime: 312 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }bool valid =true;
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1]){
               valid=false;
                break;
            }
            else{
                int temp =min(a[i],a[i+1]);
                a[i]=a[i]-temp;
                a[i+1]=a[i+1]-temp;
            }
        }
        if(valid)
        cout<<"Yes"<<endl;
        else cout<<"NO"<<endl;
    }
}
Problem: 2050E - Three Strings
Language: c++17 

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

using namespace std;

string A, B, C;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int t; cin >> t;
    while (t--){
        cin >> A >> B >> C;
        int n = A.length(), m = B.length();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MAX));
        dp[0][0] = 0;
        for (int i = 0; i <= n; ++i){
            for (int j = 0; j <= m; ++j){
                int k = i + j;
                if (k >= C.length()) continue;
                if (i < n){
                    int cost = (A[i] != C[k]) ? 1 : 0;
                    dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cost);
                }
                if (j < m){
                    int cost = (B[j] != C[k]) ? 1 : 0;
                    dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cost);
                }
            }
        }
        cout << dp[n][m] << '\n';
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;
#define fore(i, l, r)                                      \
  for (auto i = (l) - ((l) > (r)); i != (r) - ((l) > (r)); \
       i += 1 - 2 * ((l) > (r)))
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ld = long double;
using lli = long long;
using ii = pair<int, int>;

const int N = 1e3 + 5;

string a, b, c;
int mem[N][N];
int done[N][N];
int timer = 0;

int dp(int ai, int bi){
    int ci = ai + bi;
    debug(ai, bi, ci);
    if(ai > sz(a) || bi > sz(b)){
        return 2 * N + 20;
    }
    if(ci >= sz(c)){
        return 0;
    }

    auto & ans = mem[ai][bi];
    auto & vis = done[ai][bi];

    if(vis != timer){
        vis = timer;
        ans = 0;

        int conta = 0, contb = 0;
        if(a[ai] != c[ci]){
            debug( ai, a[ai], c[ci]);
            conta++;
        }
        if(b[bi] != c[ci]){
            debug(bi, b[bi], c[ci]);
            contb++;
        }

        ans = min(dp(ai + 1, bi) + conta, dp(ai, bi + 1) + contb);
    }

    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    timer = 0;
    int t; cin >> t;

    fore(_, 0, t){
        timer ++;
        cin >> a >> b >> c;

        int p = dp(0, 0);
        debug(p);
        cout << p << '\n';
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector < int > vec(n);
        for (int i = 0; i < n; i++) cin >> vec[i];
        if(vec[0]>vec[1]){
            cout<<"NO"<<endl;
        }
        else{
            bool no=false;
            for(int i = 0; i < n-1; i++){
                int mn = min(vec[i], vec[i+1]);
                vec[i] -= mn;
                vec[i+1] -= mn;
                if(vec[i]>vec[i+1]){
                    no=true;
                    break;
                }
            }
            if(no){
                cout<<"NO"<<endl;
            }
            else{
                cout<<"YES"<<endl;
            }
        }

    }
}

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

#define ll long long

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

using namespace std;



void solve() {

ll n;

cin >> n;

vector<ll> 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{

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

a[i]-=temp;

a[i+1]-=temp;

}

}

cout << "YES" << endl;

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);



int tt;

cin >> tt;

while (tt--) {

solve();

}



return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

signed main() {
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        int a[n]; int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            ans+=a[i];
        }

        vector<int>v;
        while(n>1){
            for(int i=0; i<n-1; i++) v.push_back(a[i+1]-a[i]);
            ans = max(ans,abs(accumulate(begin(v),end(v),0ll)));
            for(int i=0; i<v.size(); i++) a[i]=v[i];
            v.clear(); n--;
        }
        cout<<ans<<endl;
    }
}

Solution 2 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    
    while (t--) {
        int n;
        cin >> n;
        vector<long long> a(n);
        
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        long long res = accumulate(a.begin(), a.end(), 0LL);
        
        while (a.size() > 1) {
            vector<long long> b(a.size() - 1);
            
            for (int i = 0; i < b.size(); i++) {
                b[i] = a[i + 1] - a[i];
            }
            
            long long sum_b = accumulate(b.begin(), b.end(), 0LL);
            res = max(res, abs(sum_b));
            
            a = b;
        }
        
        cout << res << '\n';
    }
    
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <unordered_map>
using namespace std;
int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int complects;
    cin >> complects;
    //cout << complects << endl;
    vector<long long> numbersarr;
    long long n;
    long long  temp;
    long long size1;
    long long sum;
    long long summax;
    for (int j = 0; j < complects; j++) {
        //cout << "newcomplect";
        numbersarr.clear();
        cin >> n;
        //cout << n << endl;
        summax = 0;
        for (int i = 0; i < n; i++) {
            //cout << "in temp";
            cin >> temp;
            numbersarr.push_back(temp);
            //sum=a[n]-a[1]
        }
        //greedy approach
       
        sum = 0;
        size1 = numbersarr.size();
        for (int i = 0; i < numbersarr.size(); i++) {
            sum = sum + numbersarr[i];

        }
        summax = sum;
        while (size1 != 1) {
           // cout << "while";
            if (numbersarr[size1 - 1] - numbersarr[0] < numbersarr[0] - numbersarr[size1 - 1]) {
              //  cout << "3";
                reverse(numbersarr.begin(), numbersarr.end());

            }
            if (numbersarr[size1 - 1] - numbersarr[0] > summax) {
              //  cout<<"2";
                summax = numbersarr[size1 - 1] - numbersarr[0];
            }
            //do a minus
            for (int i = 0; i < numbersarr.size() - 1; i++) {
               // cout << "1";
                numbersarr[i] = numbersarr[i + 1] - numbersarr[i];

            }
            numbersarr.erase(numbersarr.end()-1);
            size1 = numbersarr.size();

        }
        cout << summax << "\n";


    }

}


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

using namespace std;

const int MAXN = 60;

int a[MAXN];

void solve(){

  int n; cin >> n;

  int ans = 0;

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

  vector<int> v;

  for(int i=1; i<=n; i++){
    v.push_back(a[i]);
  }

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

    int cur_ans = 0;

    vector<int> new_v;

    for(int i=1; i<(int) v.size(); i++){
      new_v.push_back(v[i] - v[i - 1]);
    }

    for(auto x : new_v) cur_ans += x;

    cur_ans = max(cur_ans, -cur_ans);

    ans = max(ans, cur_ans);

    v = new_v;
  }

  cout << ans << "\n";
}

int32_t main(){
  cin.tie(0)->sync_with_stdio(0);

  int t; cin >> t;

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

  return 0;
}