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

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

#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define vll vector<ll> 
#define tt   int testcase;    cin >> testcase; while (testcase--)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
ll max3(ll a, ll b, ll c) { return (max(max(a, b), c)); }
ll max4(ll a, ll b, ll c, ll d) { return (max(max(max(a, b), c), d)); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll rem(ll n , ll x) { if(x==0) return -1;
return (n<0 ? n%x+x : n%x);}
int main(){
    tt{
        int n;
        cin>>n;
        vll a(n);
        rep(i,0,n) cin>>a[i];
        ll ans=accumulate(all(a),0LL);
        for(int i=0;i<n-1;i++){
            vll b(a.size()-1);
            for(int j=0;j<a.size()-1;j++){
                b[j]=a[j+1]-a[j];
            }
            ans=max(ans,abs(accumulate(all(b),0LL)));
            a=b;
        }
        cout<<ans<<endl;

    }
    return 0;
}

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

using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI (3.141592653589)
#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i,j) for(int i = 0; i<j; i++)
#define rrep(i,j) for(int i = j; i>=0; i--)
#define all(x) x.begin(), x.end()
#define out(x) cout << x << endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define pm cout<<"-1"<<endl;

//Typedef
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int,int> mii;

// Debug Overloads
#ifdef NinjaOP
#define debug(x) _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

// Operator Overloads
template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*=======================================================================================================================================*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll lcm(ll a, ll b) {return(a*b)/gcd(a,b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*=======================================================================================================================================*/

/* ================================= CHECKER UTILITY ================================= */
bool fileCompare(const string& outPath = "output.txt", 
                const string& expPath = "expected.txt") {
    ifstream outputFile(outPath);  // Renamed from 'out'
    ifstream expectedFile(expPath); // Renamed from 'exp'
    
    if(!outputFile.is_open() || !expectedFile.is_open()) return false;
    
    string outLine, expLine;
    bool outHasMore, expHasMore;
    
    while (true) {
        outHasMore = !!getline(outputFile, outLine);
        expHasMore = !!getline(expectedFile, expLine);
        
        if(!outHasMore && !expHasMore) break;
        if(outHasMore != expHasMore) return false;
        
        // Trim trailing whitespace
        outLine.erase(outLine.find_last_not_of(" \t\r\n") + 1);
        expLine.erase(expLine.find_last_not_of(" \t\r\n") + 1);
        
        if(outLine != expLine) return false;
    }
    
    return true;
}

void runChecker() {
    cerr << (fileCompare() ? "Passed !!" : "Failed !!") << endl;
}
/* ================================= END CHECKER ================================= */

ll negativeSum2(vl& a) {
    int n = a.size();
    ll sum = 0;
    for(int i = n - 1; i >= 1; i--) {
        if(a[i] > a[i - 1]) {
            sum += a[i] - a[i - 1];
        }
    }
    
    return sum;
}

ll negativeSum1(vl& a) {
    int n = a.size();
    ll sum = 0;
    for(int i = 0; i < n - 1; i++) {
        if(a[i] > a[i + 1]) {
            sum += a[i] - a[i + 1];
        }
    }
    
    return sum;
}

void solve() {
    int n;
    cin >> n;

    vl a(n);
    cin >> a;

    ll sum = accumulate(all(a), 0LL);
    while(a.size() > 1) {
        ll orignal_neg_sum = negativeSum1(a);
        ll reverse_neg_sum = negativeSum2(a);

        if(reverse_neg_sum < orignal_neg_sum) {
            reverse(all(a));
        }

        rep(i, a.size() - 1) {
            a[i] = a[i+1] - a[i];
        }
        a.pop_back();

        sum = max(sum, accumulate(all(a), 0LL));
    }

    out(sum)
}

int32_t main()
{
    fastio();

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


    #ifdef NinjaOP 
        runChecker();
    #endif
    return 0;
}