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

Previous submission (verdict: Time limit exceeded on test 2):
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
using namespace std;
 
#define int long long
#define input(v) for(auto &it:v)cin>>it
#define output(v) for(auto &it:v)cout<<it<<" "; cout << "\n"
#define all(v) (v).begin(),(v).end()
#define vb vector<bool>
#define tzll(x) __builtin_ctzll(x)
#define lzll(x) __builtin_clzll(x)
#define lz(x) __builtin_clz(x)
#define tz(x) __builtin_ctz(x)
#define popc(x) __builtin_popcount(x)
#define popcll(x) __builtin_popcountll(x)
#define pi pair<long long, long long>
#define vi vector<long long>
#define vvi vector<vector<long long> >
#define vpi vector<pair<long long,long long> >
#define si set<long long>
#define spi set<pair<long,long> >
#define qi queue<long long>
#define qpi queue<pair<long,long> >
#define msi multiset<long long>
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull 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, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); 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 << "]";}

int gcd (int a, int b) {
    if (b == 0) return a;
    return gcd (b, a % b);
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
/*
    
*/
int rec(vi&v,int prev)
{
    int n=v.size();
    if(n==1)
    return v[0];

    vi v1,v2;
    for(int i=0;i<n-1;i++)
        v1.pb(v[i+1]-v[i]);
    for(int i=n-2;i>=0;i--)
        v2.pb(v[i]-v[i+1]);

    int res=rec(v1,0);
    if(!prev)
        res=max(res,rec(v2,1));

    return res;
}
void solve()
{
    int n;
    cin>>n;
    vi v(n);
    input(v);
    int res=accumulate(all(v),0);
    res=max(res,rec(v,0));
    cout<<res<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1; 
    cin >> t;
    for(int i = 1; i <= t; i++){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
using namespace std;
 
#define int long long
#define input(v) for(auto &it:v)cin>>it
#define output(v) for(auto &it:v)cout<<it<<" "; cout << "\n"
#define all(v) (v).begin(),(v).end()
#define vb vector<bool>
#define tzll(x) __builtin_ctzll(x)
#define lzll(x) __builtin_clzll(x)
#define lz(x) __builtin_clz(x)
#define tz(x) __builtin_ctz(x)
#define popc(x) __builtin_popcount(x)
#define popcll(x) __builtin_popcountll(x)
#define pi pair<long long, long long>
#define vi vector<long long>
#define vvi vector<vector<long long> >
#define vpi vector<pair<long long,long long> >
#define si set<long long>
#define spi set<pair<long,long> >
#define qi queue<long long>
#define qpi queue<pair<long,long> >
#define msi multiset<long long>
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull 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, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); 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 << "]";}

int gcd (int a, int b) {
    if (b == 0) return a;
    return gcd (b, a % b);
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
/*
    
*/
int rec(vi&v,int prev)
{
    int n=v.size();
    if(n==1)
    return v[0];

    vi v1,v2;
    for(int i=0;i<n-1;i++)
        v1.pb(v[i+1]-v[i]);
    for(int i=n-2;i>=0;i--)
        v2.pb(v[i]-v[i+1]);

    int res=rec(v1,0);
    if(!prev)
        res=max(res,rec(v2,1));

    return res;
}
void solve()
{
    int n;
    cin>>n;
    vi v(n);
    input(v);
    int res=accumulate(all(v),0LL);
    if(n==1)
    {
        cout<<res<<"\n";
        return;
    }
    while(v.size()>1)
    {
        vi v1,v2;
        for(int i=0;i<v.size()-1;i++)
        v1.pb(v[i+1]-v[i]);
        v=v1;
    }
    res=max({v[0],-v[0],res});
    cout<<res<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1; 
    cin >> t;
    for(int i = 1; i <= t; i++){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}