ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        int l,r,a=0,b=0,c=-1,d=0,e,f;
        cin>>l>>r;
        if(r-l==2)
        {
            cout<<l<<" "<<l+1<<" "<<r<<endl;
            continue;
        }
        bool flag=true;
        for(int i=30;i>=0;i--)
        {
            // int c=r&1<<i;
            // int d=l&1<<i;
            // cout<<i<<" _______________"<<endl;
            // cout<<c<<" "<<d<<endl;
            if(flag && (r&1<<i) && (l&1<<i))
            {
                r-=1<<i;
                l-=1<<i;
                d+=1<<i;
            }
            else if(flag && (r&1<<i))
            {
                flag=false;
                // cout<<"HII"<<endl;
                a=1<<i;
                f=r;
                continue;
            }
            e=l&1<<i;
            // cout<<c<<endl;
            if(!flag && e)
            {//cout<<"HI__"<<endl;
                b+=1<<i;
            }
            else if(!flag && e==0)
            {
                // cout<<"HII2345"<<endl;
                b+=1<<i;
                c=b-1;
                break;
            }
        }
        if(c==-1) c=b+1;
        if(a<=c || a<=b) a=f;
        cout<<a+d<<" "<<b+d<<" "<<c+d<<endl;
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<ll, ll>PII;
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int TT = 1;

ll l, r;
void sol() {
	cin >> l >> r;
	ll co = log2(r), ans = 0;
	while ((l >> co & 1) == (r >> co & 1))ans += (r >> co & 1) << co, --co;
	ans += (1 << co);
	if (ans - 1 == l)cout << l << ' ' << ans << ' ' << ans + 1 << endl;
	else cout << l << ' ' << ans - 1 << ' ' << ans << endl;
}

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

	cin >> TT;
	while (TT--)sol();
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

int main() {
	// your code goes here
int t;
cin>>t;
while(t--)
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ctr=0; int ctr2=0;
    for(int i=0;i<n-1;i++)
    {
        int sub=min(v[i],v[i+1]);
        v[i]=v[i]-sub;
        v[i+1]=v[i+1]-sub;
        if(v[i]>v[i+1])
        {
            cout<<"NO"<<endl;
            break;
        }
        else ctr++;
    }
    if(ctr==n-1)
    cout<<"YES"<<endl;
   
}
}


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

#include<algorithm>

#include<string>

using namespace std;



int main()

{

	int t;	cin >> t;

	

	while (t  --)

	{

		int n;

		cin >> n;

		int a[n];

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

		

		int u = min(a[0], a[1]);

		a[0] -= u, a[1] -= u;

		int flag = 0;

		if(a[0] > a[1]) flag = 1;

		

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

		{

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

			if(a[i] < a[i - 1]) flag = 1;

			if(a[i - 1] - p >= a[i - 2]) a[i - 1] -= p, a[i] -= p;

			else continue;

		}

		if(flag) cout << "NO" << endl;

		else cout << "YES" << endl;

	}

	return 0;

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

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

using namespace std;

#define int long long

#define lowbit(x) ((x)&(-x))

#define fi first

#define se second

const int inf=1e18;

const int N=2e5+10;

int a[N];

void solve(){

	int n;

	cin>>n;

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

	cin>>a[i];

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

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

		a[i]-=t;

		a[i+1]-=t;

	}

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

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

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

			return ;

		}

	}

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

}

signed main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T=1;

	cin>>T;

	while(T--)

	solve();

}

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

using namespace std;



#define int long long



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

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = 0;



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

        if(a[i-1] > a[i]) idx = i;

    }

    if(idx == 0){

        cout << "YES" << endl;

        return;

    }

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

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

        a[i] -= mini;

        a[i+1] -= mini;

    }

    cout << (is_sorted(all(a)) ? "YES" : "NO") << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

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

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

#endif



    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

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

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
#include <vector>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define endl "\n"

template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define out( x ) #x << " = " << x << "  "

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T, typename B = decay<decltype(*begin(declval<T>()))>, typename enable_if<!is_same<T, string>::value>::type* = nullptr>
ostream& operator <<(ostream &os, const T &c) {
	bool f = false;
	os << "(";
	for(const auto &x : c) {
		if(f) {
			os << ", ";
		}
		f = true;
		os << x;
	}return os << ")";
}

typedef long long ll;
const ll mod = 1e9 + 7;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

const int MAX_N = 1e6 + 10;

void solve() {

	int n;
	std::cin >> n;
	std::vector< int > a( n );
	for( auto& j : a ) std::cin >> j;

	int ind = n;
	for( int i=0 ; i < n -1 ; i += 1 ){
		if( a[i] <= a[i+1] ){
			a[i+1] -= a[i];
			a[i] = 0;
		}else{
			ind = i;
			break;
		}
	}

	cerr << out( a ) << endl;
	for( int i=ind ; i < n -1 ; i++ ){
		if( a[i] > a[i+1] ){
			std::cout << "NO" << endl;
			return;
		}
	}

	std::cout << "YES" << endl;



	/*
	cerr << out( a ) << endl;
	bool oke = true;
	for( int i=0 ; i < n-1 ; i++ ){
		if( a[i] > a[i+1] ){
			cerr << out( i ) << out( a[i] ) << out( a[i+1] ) << endl;
			if( !i ){
				oke = false;
				continue;
			}

			if( a[i-1] <= a[i] ){
				a[i] -= a[i-1];
				a[i-1] = 0;
			}else{
				oke = false;
			}

			cerr << out( a[i-1] ) << out( a[i] ) << endl;
			if( a[i] > a[i+1] ){
				oke = false;
			}
		}
		if( !oke ){
			std::cout << "NO" << endl;
			return;
		}
	}

	std::cout << "YES" << endl;
	*/

}

signed main() {
#ifndef LOCAL
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

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

	return 0;
}


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

using namespace std;



int main()

{

    int t;

      cin>>t;

      while(t--)

      {

         int flag=1;

         int n;

         cin>>n;

         int A[n];

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

         {

         cin>>A[i];

         }



         if(A[1]<A[0])

         {

            cout<<"NO"<<endl;

            goto end;

         }



         



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

         {

          if(A[i+1]-A[i]<=A[i+2])

          {

            flag=1;

          }

          else

          {

            flag=0;

            break;

          }

          A[i+1]=A[i+1]-A[i];

         }



         if(flag==1)

         {

            cout<<"YES"<<endl;

         }

         else

         {

            cout<<"NO"<<endl;

         }

          end:;

      }

   return 0;

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

Solution 1 (runtime: 46 ms):


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

#ifndef ONLINE_JUDGE
#else
#define debug(...)
#define Timer(...)
#endif

int solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = accumulate(a.begin(), a.end(), 0);

    for (int i = 0; a.size() > 1; i++)
    {
        ans = max(ans, abs(a.back() - a[0]));

        vector<int> b;
        for (int j = 1; j < a.size(); j++)
        {
            b.emplace_back(a[j] - a[j - 1]);
        }
        swap(a, b);
    }
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        cout << solve() << "\n";
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define vectinp(v){for(auto&i:v){cin>> i;}}
#define PrintVec(v){for(auto&i:v){cout<< i<<" ";}cout<< endl;}
#define vi vector<int> 
#define vll vector<long long>
#define vpii vector<pair<int,int>> 
#define vpll vector<pair<long long ,long long >>
#define mpll map<long long,long long>
#define umpll unordered_map<long long ,long long>
#define mapii map<int,int> 
#define u_mapii unordered_map<int,int> 
#define ll long long
#define itc int t; \
            cin>> t;\
            while(t--)

#define yes cout << "Yes\n"
#define no cout << "No\n"
#define all(v) v.begin(),v.end()
#define sz(x) (int)(x.size())

void solve(){
    int n;
    cin>>n;
    vll v(n),bucket; 
    vectinp(v);
    ll ans = accumulate(all(v),0); 
    
    while( n > 1 ){
        ll sum = 0  ;
        for(int i=0;i<n-1;i++){
            bucket.push_back(v[i+1]-v[i]);
            sum+=(v[i+1]-v[i]);
        }

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

        for(int i=0;i<n-1;i++){
            v[i] = bucket[i];
        }

        bucket.clear();
        n--;
    }
    cout << ans<<endl;

}
int main(){
    itc{
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using str = string;
#define vec vector
#define arr array
#define all(x) x.begin(), x.end()
#define p(x) cout << (x) << endl
#define pv(x) for(auto& _:x){cout<<(_)<<' ';}cout<<endl;

#ifdef LOCAL
#include "debug.cpp"
#else
#define d(x) 69
#endif

void solve() {
	int l,r; cin>>l>>r;
	bitset<32> a(l), b(l), diff(l^r);
	int i=29;
	while(diff[i]!=1 and i>=0) i--;
	a[i]=0; b[i]=1;
	for(int j=i-1; j>=0; j--){
		a[j]=1; b[j]=0;
	}
	int aa = a.to_ulong(); d(aa);
	int bb = b.to_ulong(); d(bb);
	int c=l;
	while(c==aa or c==bb) c++;
	d(c);
	vec<int> out = {aa,bb,c};	
	pv(out);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t; cin>>t; while(t--)solve();
}


Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define endl '\n'
typedef pair<int,int> PII;
void solve(){
	int l,r;cin>>l>>r;
	int x=1;
	while(x*2<=r) x<<=1;
	int num=0;
	while(num+x-1<l||num+x>r){
		if(num+x<=r) num+=x;
		x>>=1;
	}
	num+=x;
	int a,b,c;
	if(num+1<=r) a=num+1,b=num,c=num-1;
	else a=num,b=num-1,c=num-2;
	cout<<a<<" "<<b<<" "<<c<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 92 ms):
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define fi first
#define se second
#define PII pair<int,int>
#define ALL(x) x.begin(),x.end()
const int N=2e5+10;

void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a.begin(),a.end()-n+r);
    sort(b.begin()+l-1,b.end());
    int ans=0;
    for(int i=0;i<r-l+1;i++)  ans+=a[i];
    int tt=0;
    for(int i=l-1;i<r;i++)  tt+=b[i];
    ans=min(tt,ans);
    cout<<ans<<'\n';
}

signed main()
{
    IOS
    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

Solution 2 (runtime: 77 ms):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int a,l,r;
	cin >> a >> l >> r;
	vector<long long> input(a);
	vector<long long> left(r);
	vector<long long> right(a-l+1);
	for(int i=0;i<a;i++){
		cin >> input[i];
		if(i<r){
			left[i] = input[i];
		}
		if(i>=l-1){
			right[i-l+1] = input[i];
		}
	}
	sort(left.begin(),left.end());
	sort(right.begin(),right.end());
	long long mx=0,mx2=0;
	for(int i=0;i<=r-l;i++){
		mx+=left[i];
	}
	for(int i=0;i<=r-l;i++){
		mx2+=right[i];
	}
	cout << min(mx,mx2) << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
#define uld unsigned long double
#define all(x) (x).begin(), (x).end()
#define dsort(x) sort(all(x), greater<>())
#define rev(x) reverse(all(x))
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define ff first
#define ss second
#define vec vector
#define uset unordered_set
#define umap unordered_map
#define ummap unordered_multimap
#define pb push_back
#define pf push_front
#define str string
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}



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


	int t;
	cin >> t;
	while(t--) {
		int n;
		cin>>n;
		vec<int> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(i>0) {
				int m=min(a[i-1],a[i]);
				a[i-1]-=m;
				a[i]-=m;
			}
		}

		bool no=false;	
		for(int i=0;i<n-1;i++){
			if(a[i]>a[i+1]) {
				no=true;
				break;
			}
		}
		if(!no) cout<<"YES\n";
		else cout<<"NO\n";

	}
	

    return 0;
}

Solution 2 (runtime: 390 ms):
#include<iostream>
#include<vector>
#include<climits>

#define vi vector<int> 
#define vll vector<ll>  
#define ll long long   

using namespace std;
char ln = '\n';

void solve()
{
  int n ;cin >> n;
  vi a(n);
  for(int& i :a)
  {
    cin >> i;
  }
  for(int i = 0; i < n-1 ; i++)
  {
    if(a[i] > a[i+1] && i==0)
    {
      cout << "No" <<ln;
      return;
    }
    else
    {
      int minVal = min(a[i],a[i+1]);
      a[i+1] -=minVal;
      a[i] -=minVal;
    }
    
  }
  for(int i = 0 ; i < n-1; i++)
  {
    if(a[i] > a[i+1])
    {
      cout << "No" <<ln;
      return;
    }
  }
  cout << "Yes"<<ln;
}

int main() 
{
    ll t;
    cin >> t;
    while(t--) solve();
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
int t, n, a[500010];
int main(){
	scanf("%d", &t);
	for(; t--; ){
		long long sum = 0;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]), sum += a[i];
		long long ans = sum;
		int len = n;
		if(len > 1){
			while(len){
				sum = 0;
				for(int i = 1;i <= len; i++)
					sum += a[i];
				ans = max(ans, max(sum, -sum));
				for(int i = 1; i < len; i++)
					a[i] = a[i + 1] - a[i];
				--len;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Solution 2 (runtime: 62 ms):
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;
void solve()
{
    int n,ans=0;
    cin>>n;
    vector<int> a(n,0),b;
    for(int i=0;i<n;i++)
        cin>>a[i],ans+=a[i];
    for(int i=1;i<n;i++)
    {
        ans=max(ans,max(a[n-i]-a[0],a[0]-a[n-i]));
        for(int j=0;j<=n-i-1;j++)
            a[j]=a[j+1]-a[j];
    }
    cout<<ans<<'\n';
}
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
// MULHAM
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
//------------------------------------||

void solve(){
    string s;
    cin >> s;
    int sum = 0,tow=0,three=0;
    for (int i = 0; i < s.length(); i++){
        string ss = "";
        ss += s[i];
        sum += stoi(ss);
        if (ss=="2")
            tow++;
        else if (ss=="3")
             three++;
    }
    ////////////////////////////////////////
    bool is = false;
    if (sum%9==0)
        is= 1;
    while (three--){
        if(sum%9==7&&tow)
            is = 1;
        if (sum%9==5&&tow>1)
            is = 1;
         sum += 6;
          if (sum%9==0)
          is = 1;
    }   
     if (sum%9==0)
          is = 1;
    while (tow--)
    {
      if (sum%9==0)
          is = 1;
      sum += 2;
       if (sum%9==0)
          is = 1;
    }
       if (sum%9==0)
          is = 1;
    
    if (is)
        cout << "YES\n";
    else
        cout << "NO\n";
}

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

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

bool f(int level, int sum, int n, string &st, vector<vector<long long>> &dp) {
    if (level == n) {
        return sum == 0;
    }

    if (dp[level][sum % 9] != -1) {
        return dp[level][sum % 9];
    }

    bool ans = false;
    int temp = st[level] - '0';
    if (f(level + 1, (sum + temp) % 9, n, st, dp)) {
        ans = true;
    }
    if (temp <= 3) {
        if (f(level + 1, (sum + temp * temp) % 9, n, st, dp)) {
            ans = true;
        }
    }

    return dp[level][sum % 9] = ans;
}

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

        int n = s.size();

        vector<vector<long long>> dp(n + 1, vector<long long>(9, -1));

        if (f(0, 0, n, s, dp)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t>0){
        int n;
        cin>>n;
        vector<long long> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int 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 = (sum + a[j]) ;
            if (i == 0) ans = max(ans, sum);
            else ans = max(ans, max(sum, ( - sum) ));
            for (int j = 0; j <now-1; j++) a[j] = (a[j + 1] - a[j]) ;
            now--;
        }
        cout<<ans<<endl;
        t--;
    }
}

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

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

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

Solution 1 (runtime: 46 ms):
#include<iostream>
#include<algorithm>
#include<cstring>
#define int long long
using namespace std;
int a[100];
signed main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int ans=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			ans+=a[i];
		}
		if(n==1){
			cout<<ans<<"\n";//不能进行1，2操作
			continue;
		}
		while(n){
			n--;
			for(int i=1;i<=n;i++){
				a[i]=a[i+1]-a[i];//2操作
			}
			int sum=0;
			for(int i=1;i<=n;i++) sum+=a[i];
			ans=max(ans,max(sum,-sum));//是否进行1操作
		}
		cout<<ans<<"\n";
			}
return 0;
} 

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

long long int max_sum(long long int arr[], long long int n){
    if(n==1){
        return arr[0];
    }
    long long int sum=0;
    for(int i=0; i<n; i++){
        sum+=arr[i];
    }
    long long int diff[n-1];
    for(int i=0; i<n-1; i++){
        diff[i]=arr[i+1]-arr[i];
    }
    return max(abs(sum),abs(max_sum(diff,n-1)));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    for(int tc=0; tc<t; tc++){
        long long int n;
        cin >> n;
        long long int arr[n];
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        if(n==1){
            cout << arr[0] << "\n";
        }
        else if(n==2){
            cout << max(arr[0]+arr[1],abs(arr[1]-arr[0])) << "\n";
        }
        else{
            long long int s1=0;
            for(int i=0; i<n; i++){
                s1+=arr[i];
            }
            long long int diff1[n-1];
            for(int i=0; i<n-1; i++){
                diff1[i]=arr[i+1]-arr[i];
            }
            long long int ans=max(s1,max_sum(diff1,n-1));
            cout << ans << "\n";
        }
    }
}