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

Previous submission (verdict: Wrong answer on test 5):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define _USE_MATH_DEFINES
#define dbg(v) cerr << "Line(" << __LINE__ << ") -> " << "#var" << " = " << (v) << endl;
#define dbg_test(v) cerr << "Line(" << __LINE__ << ") -> " << "#Test" << " = " << (v) << endl;
#define dbg_time(v) cerr << "Line(" << __LINE__ << ") -> " << "#Time" << " = " << (v) << endl;
#define dbg1(u, v) cerr << "Line(" << __LINE__ << ") -> " << "u" << " = " << (u) << ' ' << "v" << " = " << (v) << endl;
#define int long long
#define endl "\n"
#define vec vector
#define pb push_back
#define INF INT_MAX
#define se second
#define fi first
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define str string
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define all(a) (a).begin(), (a).end()
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define sz(a) (a).size()
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define rep(a, n) for (ll i = a; i < n; i++)
#define REP(a, n) for (ll i = a; i <= n; i++)
#define rall(a) (a).rbegin(), (a).rend()
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
const long double EPS = 1e-6;

using namespace std;

void solve() {
    int n; cin >> n;
    vec<int> a(n);
    for (auto& p : a) {
        cin >> p;
    }
    if (n == 1) {
        cout << a[n - 1] << endl;
        return;
    }
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i+=2) {
        sum1 += a[i];
        if (i + 1 < n) sum2 += a[i + 1];
    }
    int ans = sum1 + sum2;
    while (a.size() > 1) {
        int sum = 0, psum = 0;
        for (int i = 0; i < a.size() - 1; i++) {
            sum += a[i + 1] - a[i];
        }
        reverse(all(a));
        for (int i = 0; i < a.size() - 1; i++) {
            psum += a[i + 1] - a[i];
        }
        if (psum >= ans) {
            for (int i = 0; i < a.size() - 1; i++) {
                a[i] = a[i + 1] - a[i];
            }
            a.pop_back();
            ans = psum;
            continue;
        }
        else if (sum >= ans) {
            reverse(all(a));
            for (int i = 0; i < a.size() - 1; i++) {
                a[i] = a[i + 1] - a[i];
            }
            a.pop_back();
            ans = sum;
            continue;
        }
        reverse(all(a));
        for (int i = 0; i < a.size() - 1; i++) {
            a[i] = a[i + 1] - a[i];
        }
        a.pop_back();
    }
    cout << ans << endl;
    return;
}


signed main() {
#ifdef LOCAL
    freopen("cows.in", "r", stdin);
    freopen("cows.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t; cin >> t;
    for (int i = 0; i < t; ++i)
    solve();
}


Submission (verdict: Wrong answer on test 6):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define _USE_MATH_DEFINES
#define dbg(v) cerr << "Line(" << __LINE__ << ") -> " << "#var" << " = " << (v) << endl;
#define dbg_test(v) cerr << "Line(" << __LINE__ << ") -> " << "#Test" << " = " << (v) << endl;
#define dbg_time(v) cerr << "Line(" << __LINE__ << ") -> " << "#Time" << " = " << (v) << endl;
#define dbg1(u, v) cerr << "Line(" << __LINE__ << ") -> " << "u" << " = " << (u) << ' ' << "v" << " = " << (v) << endl;
#define int long long
#define endl "\n"
#define vec vector
#define pb push_back
#define INF INT_MAX
#define se second
#define fi first
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define str string
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define all(a) (a).begin(), (a).end()
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define sz(a) (a).size()
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define rep(a, n) for (ll i = a; i < n; i++)
#define REP(a, n) for (ll i = a; i <= n; i++)
#define rall(a) (a).rbegin(), (a).rend()
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
const long double EPS = 1e-6;

using namespace std;

void solve() {
    int n; cin >> n;
    vec<int> a(n);
    for (auto& p : a) {
        cin >> p;
    }
    if (n == 1) {
        cout << a[n - 1] << endl;
        return;
    }
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i+=2) {
        sum1 += a[i];
        if (i + 1 < n) sum2 += a[i + 1];
    }
    if (n == 2) {
        cout << max(max(abs(sum2) + sum1, sum1 + sum2), sum2 - sum1) << endl;
        return;
    }
    int ans = sum1 + sum2;
    while (a.size() > 1) {
        int sum = 0, psum = 0;
        for (int i = 0; i < a.size() - 1; i++) {
            sum += a[i + 1] - a[i];
        }
        reverse(all(a));
        for (int i = 0; i < a.size() - 1; i++) {
            psum += a[i + 1] - a[i];
        }
        if (psum >= ans) {
            for (int i = 0; i < a.size() - 1; i++) {
                a[i] = a[i + 1] - a[i];
            }
            a.pop_back();
            ans = psum;
            continue;
        }
        else if (sum >= ans) {
            reverse(all(a));
            for (int i = 0; i < a.size() - 1; i++) {
                a[i] = a[i + 1] - a[i];
            }
            a.pop_back();
            ans = sum;
            continue;
        }
        reverse(all(a));
        for (int i = 0; i < a.size() - 1; i++) {
            a[i] = a[i + 1] - a[i];
        }
        a.pop_back();
    }
    cout << ans << endl;
    return;
}


signed main() {
#ifdef LOCAL
    freopen("cows.in", "r", stdin);
    freopen("cows.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t; cin >> t;
    for (int i = 0; i < t; ++i)
    solve();
}