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

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

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

    long long t;
    cin >> t;
    
    while (t--) {
        long long n, sum = 0;
        cin >> n;

        vector<long long> a(n);
        for (long long i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
        }

        vector<long long> v;
        bool b = true;
        long long currentSize = n;

        while (--currentSize) {
            long long s2 = 0;
            
            if (b) {
                v.clear();
                for (long long i = 0; i < currentSize; i++) {
                    v.push_back(a[i + 1] - a[i]);
                    s2 += v[i];
                }
                b = false;
            } else {
                a.clear();
                for (long long i = 0; i < currentSize; i++) {
                    a.push_back(v[i + 1] - v[i]);
                    s2 += a[i];
                }
                b = true;
            }

            sum = max(sum, abs(s2));
        }

        cout << sum << endl;
    }

    return 0;
}


Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
 
// PBDS:
#include <ext/pb_ds/assoc_container.hpp> // find_by_order(x) = s[x]
#include <ext/pb_ds/tree_policy.hpp>     // order_of_key(x)  = # of elements strictly smaller than x
using namespace __gnu_pbds;
template<typename dataType>
using ordered_set = tree<dataType, null_type, less<dataType>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename dataType1, typename dataType2>
using ordered_map = tree<dataType1, dataType2, less<dataType1>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename dataType>
using ordered_multiset = tree<dataType, null_type, less_equal<dataType>, rb_tree_tag, tree_order_statistics_node_update>;
 
 
typedef long long int         ll;
typedef long double           ld;
typedef pair<int, int>          pi;
typedef vector<int>            vi;
typedef vector<ll>            vll;
typedef vector<vector<int>>    vvi;
typedef vector<pair<int, int>>  vpi;
typedef vector<bool>          vb;
 
#define pb            push_back
#define pf            push_front
#define all(x)        begin(x), end(x)
#define sz(x)         (int)(x).size()
#define ff            first
#define ss            second
#define mp            make_pair
#define mt            make_tuple
#define lb            lower_bound
#define ub            upper_bound
#define Tcase()       int tcc; cin >> tcc; while(tcc--)
#define FOR(i, a, b)  for(ll i = (a); i < (b); i++)
#define F0R(i, a)     FOR(i, 0, a)
#define YES           cout << "YES\n"
#define NO            cout << "NO\n"
#define lcm(a, b)     ((a / __gcd(a, b)) * b)
#define rrep(i, a, b)  for(ll i = (a); i < (b); i++)
#define rep(i, a)     FOR(i, 0, a)
 
ll  MOD   = 1e9 + 7;   //998244353
const ll  INF   = 9e18;
const int MX    = 2e5 + 5;
const ld  PI    = acos((ld) -1);
const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
 
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
 
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1LL; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modDiv(ll a, ll b) { return modMul(a, modPow(b, MOD-2)); }
 
 
ll Bigmod(ll a, ll b, ll m){
    if(b == 0) return 1 % m;
    ll x = Bigmod(a, b / 2LL, m);
    x = (x * x) % m;
    if(b % 2 == 1) x = (x * a) % m;
    return x;
}
void C(int ttt){
    int n,nn; ll ans=-INF; cin>>n; nn=n; vll a(n); rep(i,n) cin>>a[i];
    if(n==1) {cout << a[0] << endl; return;}
    rep(i,n){
        ll z=0;
        rep(i,nn){
            z+=a[i];
        }
        if(i==0) ans=max(z,ans);
        else ans=max(ans,max(z,(-z)));
        rep(i,nn-1){
            a[i]=a[i+1]-a[i];
        }
        nn--;
    }
    cout << ans << endl;
}
int main(){
    setIO();
    int ttt=1;
    Tcase()
        C(ttt++);
}