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

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

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

int binExp(int a, int b){
	int ans = 1;
	while(b){
		if(b&1){
			ans = (ans*1LL*a)%M;
		}
		a = (a*1LL*a)%M;
		b>>=1;
	}
	return ans;
}


void solve(){
	int n;
    cin>>n;
    vector<ll> a(n);
    ll sum =0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        sum += a[i];
    }
    
    while(a.size() > 1){
        vector<ll> newA(a.size()-1);
        ll newSum = 0;
        for (int i = 0; i < a.size() -1 ; ++i)
        {
            newA[i] = a[i+1] - a[i];
            newSum += newA[i];
        }
        sum = max(sum , abs(newSum));

        a = newA;
    }

    cout<<sum<<endl;
}	



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>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

/* clang-format off */

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
#define Graph unordered_map<int,vector<int>>

/* FUNCTIONS */
#define f(i,s,e) or(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()

/* PRINTS */
template <class T>
void print_v(vector<T> &v) { for (auto x : v) cout << x << " "; cout << endl; }
//void print(vector<T> &v){ for(auto x : v) cout << x <<" "; cout << endl; }

/* UTILS */
#define MOD 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
//pbds s; same as ordered set
// s.order_of_key(k) find index of element value k
//cout<<*(s.find_by_order(k)) value of element at index k
ll min(ll a,int b) { if (a<b) return a; return b; }
ll min(int a,ll b) { if (a<b) return a; return b; }
ll max(ll a,int b) { if (a>b) return a; return b; }
ll max(int a,ll b) { if (a>b) return a; return b; }
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }

//fast exponanation
ll power(int a,int b){
    //log(b)
    if(!b){
        return 1;
    }
    //a%=MOD;
    ll half_power=power(a,b/2);
    if(b%2==0){
        return( half_power*half_power)%MOD;
    }
    return ((half_power*half_power)%MOD*a%MOD)%MOD;
}

int bitLength(int x){ return (int)log2(x)+1;} 
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }
int findComplement(int num) { int t=bitLength(num); unsigned int mask=(1U<<t)-1; return num^mask;}

/*  All Required define Pre-Processors and typedef Constants */
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

/*
            WHITEBOARD



*/
/* clang-format on */
void test_case()
{
    // WRITE CODE HERE
    ll n;
    cin>>n;
    vll arr(n,0);
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    ll ans=accumulate(all(arr),0LL);
    while(arr.size()>1) {
        ll sum1=0;
        ll sum2=0;
        vll b,c;
        for(int i=0;i<arr.size()-1;i++) {
            ll temp=arr[i+1]-arr[i];
            sum1+=temp;
            b.push_back(temp);
        }
        for(int i=arr.size()-1;i>0;i--) {
            ll temp=arr[i-1]-arr[i];
            sum2+=temp;
            c.push_back(temp); 
        }
        if(sum1>sum2) {
            arr=b;
            ans=max(ans,sum1);
        }
        else{
            arr=c;
            ans=max(ans,sum2);
        }
    }
    cout<<ans<<endl;


}
/* Main()  function */
int main()
{

    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc;
    cin>>tc;
    while(tc--){
        test_case();
    }
    return 0;
}