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

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define double long double
#define endl '\n'
#define vin(a) for(int i=0;i<(a).size();i++)cin>>a[i];
#define vout(a) for(int i=0;i<a.size();i++)cout<<a[i]<<' ';cout<<endl;
#define sin(a,n) for(int i=0;i<n;i++){int temp;cin>>temp;a.insert(temp);}
#define sout(a) for(auto i:a)cout<< i<<' ';cout<<endl;
#define cout(x) cout<<setprecision(20)<<x<<endl 
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(),greater<int>()
#define pyes cout<<"YES"<<endl;
#define pno cout<<"NO"<<endl;
#define p(x) cout<<x<<endl;
#define pb push_back
const int M = 1000000007;
const int N = 1e5+10;

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
        cin>>n;
        vector<int> v(n);
        vin(v)
        vector<int> pl=v;
        int sum=accumulate(all(v),0LL);
        while(pl.size()>1){
            int rev=0;
            for(int i=0;i<pl.size()-1;i++){
                rev+=pl[i+1]-pl[i];
            }
            if(rev>=0){
                vector<int> m;
                for(int i=0;i<pl.size()-1;i++){
                    m.pb(pl[i+1]-pl[i]);

                }
                sum=max(sum,accumulate(all(m),0LL));
                pl.clear();
                pl=m;
            }
            else{
                reverse(all(pl));
            }
        }
        p(sum)
	}
    return 0;
}

Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define sc second
#define PI acos(-1.0)
#define MOD 1000000007
#define endl '\n'
#define eb emplace_back
#define set(n, k) (n = (1LL << k))
#define unset(n, k) (n &= ~(1LL << k))
#define check(n , k) (n & (1LL << k))
#define toggle(n, k) (n ^ (1LL << k))
#define fastio std::ios_base::sync_with_stdio (false); cin.tie(0); cout.tie(0);
int popcount(ll n) {return __builtin_popcountll(n);}
int poplow(ll n) {return __builtin_ctzll(n);}
int pophigh(ll n) {return 63 - __builtin_ctzll(n);}
ll PERFECT_NUM[]={6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128};
//-----------------------------------------------------------------------------------
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return ((a/gcd(a,b))*b);
}

ll BigMod(ll a, ll p, ll m){
    ll ret=1;
    while(p){
        if(p&1) ret=((ret%m)*(a%m))%m;
        a=((a%m)*(a%m))%m;
        p/=2;
    }
    return ret;
}
ll AddMul(ll a, ll p, ll m){
    ll ret=0;
    while(p){
        if(p&1) ret=((ret%m)+(a%m))%m;
        a=((a%m)+(a%m))%m;
        p /= 2;
    }
    return ret;
}
void iofile(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
//-------------------------------------------------------------------------
 /*TO GET SOMETHING YOU NEVER HAD YOU HAVE TO DO SOMETHING YOU NEVER DID*/
//-------------------------------------------------------------------------

map<vector<ll>, ll>dp;

ll dpkoro(vector<ll>v){
    if(v.size() == 1) return v[0];
    if(dp.find(v) != dp.end()) return dp[v];

    ll x = 0;
    for(int i = 0; i < v.size(); i++) x += v[i];

    vector<ll>vv;
    ll m = v.size();
    for(int i = 1; i < m; i++){
        vv.push_back(v[i] - v[i-1]);
    }
    x = max(x, dpkoro(vv));
    vv.clear();

    for(int i = m-2; i >= 0; i--){
        vv.push_back(v[i] - v[i+1]);
    }
    x = max(x, dpkoro(vv));

    return dp[v] = x;
}

void solve(){
    int n; cin>>n;
    vector<ll>v(n);

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

    cout<<dpkoro(v)<<endl;
}


int main(){
    fastio;
    iofile();
    int t=1, tc=1;
    cin>>t;
    //cin.ignore();
    while(t--){
        //cout<<"Case "<<tc++<<": ";
        solve();
    }

    return 0;
}