Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
using namespace std;

/*
 ######   #####    ##  ##    ###      ###    ##   ##           ####       ###    ### ###   ##  ##   #####    # #####  ######  ###  ###   ###    
   ##    ##   ##   ##  ##   ## ##    ## ##   ###  ##            ##       ## ##    ## ##    ##  ##  ### ###  ## ## ##    ##     ##  ##   ## ##   
   ##    ##        ##  ##  ##   ##  ##   ##  #### ##            ##      ##   ##   ####     ##  ##  ##   ##     ##       ##      ####   ##   ##  
   ##     #####    ######  ##   ##  ##   ##  #######            ##      ##   ##   ###      ######  ##   ##     ##       ##       ##    ##   ##  
   ##         ##   ##  ##  #######  #######  ## ####            ##      #######   ####     ##  ##  ##   ##     ##       ##       ##    #######  
   ##    ##   ##   ##  ##  ##   ##  ##   ##  ##  ###            ##  ##  ##   ##   ## ##    ##  ##  ### ###     ##       ##       ##    ##   ##  
 ######   #####    ##  ##  ##   ##  ##   ##  ##   ##           #######  ##   ##  ### ###   ##  ##   #####     ####    ######    ####   ##   ##  
                                                                                                                                                
*/

//Speed
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Solve cout.tie(NULL);

//Aliases
using ll= long long;
using lld= long double;
using ull= unsigned long long;

//Constants
const lld pi= 3.141592653589793238;
const ll INF= LONG_MAX;
const ll mod=1e9+7;

//TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;

// Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fil(i,m,n) for(int i=m;i<n;i++)
#define fl(i,n) for(int i=0;i<n;i++)
#define rl(i,m,n) for(int i=n;i>=m;i--)
#define py cout<<"YES\n";
#define pm cout<<"-1\n";
#define pn cout<<"NO\n";
#define vr(v) v.begin(),v.end()
#define rv(v) v.end(),v.begin()
#define ret(msg) cout << msg << "\n"; return

// Operator overloads
template<typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }
template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}
template<typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }

// Utility functions
template <typename T>
void print(T &&t)  { cout << t << "\n"; }
void printarr(ll arr[], ll n){fl(i,n) cout << arr[i] << " ";cout << "\n";}
template<typename T>
void printvec(vector<T>v){ll n=v.size();fl(i,n)cout<<v[i]<<" ";cout<<"\n";}
template<typename T>
ll sumvec(vector<T>v){ll n=v.size();ll s=0;fl(i,n)s+=v[i];return s;}

// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} //__gcd 
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}

//Sorting
bool sorta(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
bool sortd(const pair<int,int> &a,const pair<int,int> &b){return (a.second > b.second);}

//Bits
string decToBinary(int n){string s="";int i = 0;while (n > 0) {s =to_string(n % 2)+s;n = n / 2;i++;}return s;}
ll binaryToDecimal(string n){string num = n;ll dec_value = 0;int base = 1;int len = num.length();for(int i = len - 1; i >= 0; i--){if (num[i] == '1')dec_value += base;base = base * 2;}return dec_value;}

//Check
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}

void fun(vector<ll>& ans,vector<ll> a){
    if(a.size()==1){
        ans.push_back(a[0]);
        return;
    }
    vector<ll> a1;
    ll s1=0,s2=0,s3=0;
    for(ll i=1;i<a.size();i++){
        a1.push_back(a[i]-a[i-1]);
        s1+=a[i]-a[i-1];
    }
    for(ll i=0;i<a.size();i++){
        s3+=a[i];
    }
    vector<ll> a2=a;
    reverse(a2.begin(),a2.end());
    vector<ll> a3;
    for(ll i=1;i<a.size();i++){
        s2+=(a2[i]-a2[i-1]);
        a3.push_back(a2[i]-a2[i-1]);
    }
    ans.push_back(s1);
    ans.push_back(s2);
    ans.push_back(s3);
    fun(ans,a1);
    fun(ans,a3);
}

void solve() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    fl(i,n) cin>>a[i];
    vector<ll> ans;
    fun(ans,a);
    cout<<*max_element(ans.begin(),ans.end())<<endl;
}

int main()
{
    Code By Solve
    ll t;
    cin>>t;
    fl(i,t)
    {
        solve();
    }
return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

/*
 ######   #####    ##  ##    ###      ###    ##   ##           ####       ###    ### ###   ##  ##   #####    # #####  ######  ###  ###   ###    
   ##    ##   ##   ##  ##   ## ##    ## ##   ###  ##            ##       ## ##    ## ##    ##  ##  ### ###  ## ## ##    ##     ##  ##   ## ##   
   ##    ##        ##  ##  ##   ##  ##   ##  #### ##            ##      ##   ##   ####     ##  ##  ##   ##     ##       ##      ####   ##   ##  
   ##     #####    ######  ##   ##  ##   ##  #######            ##      ##   ##   ###      ######  ##   ##     ##       ##       ##    ##   ##  
   ##         ##   ##  ##  #######  #######  ## ####            ##      #######   ####     ##  ##  ##   ##     ##       ##       ##    #######  
   ##    ##   ##   ##  ##  ##   ##  ##   ##  ##  ###            ##  ##  ##   ##   ## ##    ##  ##  ### ###     ##       ##       ##    ##   ##  
 ######   #####    ##  ##  ##   ##  ##   ##  ##   ##           #######  ##   ##  ### ###   ##  ##   #####     ####    ######    ####   ##   ##  
                                                                                                                                                
*/

//Speed
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Solve cout.tie(NULL);

//Aliases
using ll= long long;
using lld= long double;
using ull= unsigned long long;

//Constants
const lld pi= 3.141592653589793238;
const ll INF= LONG_MAX;
const ll mod=1e9+7;

//TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;

// Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fil(i,m,n) for(int i=m;i<n;i++)
#define fl(i,n) for(int i=0;i<n;i++)
#define rl(i,m,n) for(int i=n;i>=m;i--)
#define py cout<<"YES\n";
#define pm cout<<"-1\n";
#define pn cout<<"NO\n";
#define vr(v) v.begin(),v.end()
#define rv(v) v.end(),v.begin()
#define ret(msg) cout << msg << "\n"; return

// Operator overloads
template<typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }
template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}
template<typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }

// Utility functions
template <typename T>
void print(T &&t)  { cout << t << "\n"; }
void printarr(ll arr[], ll n){fl(i,n) cout << arr[i] << " ";cout << "\n";}
template<typename T>
void printvec(vector<T>v){ll n=v.size();fl(i,n)cout<<v[i]<<" ";cout<<"\n";}
template<typename T>
ll sumvec(vector<T>v){ll n=v.size();ll s=0;fl(i,n)s+=v[i];return s;}

// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} //__gcd 
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}

//Sorting
bool sorta(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
bool sortd(const pair<int,int> &a,const pair<int,int> &b){return (a.second > b.second);}

//Bits
string decToBinary(int n){string s="";int i = 0;while (n > 0) {s =to_string(n % 2)+s;n = n / 2;i++;}return s;}
ll binaryToDecimal(string n){string num = n;ll dec_value = 0;int base = 1;int len = num.length();for(int i = len - 1; i >= 0; i--){if (num[i] == '1')dec_value += base;base = base * 2;}return dec_value;}

//Check
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}

void fun(vector<ll>& ans,vector<ll> a){
    if(a.size()==1){
        ans.push_back(a[0]);
        ans.push_back(-a[0]);
        return;
    }
    vector<ll> a1;
    ll s1=0,s2=0,s3=0;
    for(ll i=1;i<a.size();i++){
        a1.push_back(a[i]-a[i-1]);
        s1+=a[i]-a[i-1];
    }
    for(ll i=0;i<a.size();i++){
        s3+=a[i];
    }
    ans.push_back(max(s1,s2));
    ans.push_back(s3);
    fun(ans,a1);
}

void solve() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    fl(i,n) cin>>a[i];
    if(n==1){
        cout<<a[0]<<endl;
        return;
    }
    vector<ll> ans;
    fun(ans,a);
    cout<<*max_element(ans.begin(),ans.end())<<endl;
}

int main()
{
    Code By Solve
    ll t;
    cin>>t;
    fl(i,t)
    {
        solve();
    }
return 0;
}