Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned ll

#define v vector
#define vll vector<ll>
#define vb vector<bool>

#define p pair
#define pll pair<ll, ll>

#define uset unordered_set
#define umap unordered_map
#define sll set<ll>
#define mpll map<ll, ll>

#define dqll deque<ll>
#define stll stack<ll>
#define qll queue<ll>

#define fi first
#define se second

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define all(x) (x).begin(), (x).end()

using namespace std;

// STRUCTS & CLASSES
///////////////////////////////////////////////////////////////////////////



// GLOBALS
///////////////////////////////////////////////////////////////////////////

ll n, t;
vll arr;

// HELPER FUNCS
///////////////////////////////////////////////////////////////////////////

vll diff(vll& arr)
{
    vll res(arr.size() - 1);
    for (ll i = 0; i < arr.size() - 1; i++)
    {
        res[i] = arr[i + 1] - arr[i];
    }
    return res;
}

ll sum(vll& arr)
{
    ll res = 0;
    for (auto i : arr)
    {
        res += i;
    }
    return res;
}

ll solve(vll& arr, ll depth = 0)
{
    if (arr.size() == 1)
    {
        return arr[0];
    }

    ll s = sum(arr);
    vll d = diff(arr);
    ll s1 = solve(d, depth + 1);

    if (depth = 0)
    {
        return max(s, abs(s1));
    }
    else
    {
        return max(abs(s), abs(s1));
    }
}

// MAIN
///////////////////////////////////////////////////////////////////////////

int main()
{
    fastio;
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);

    // input
    cin >> t;

    // solve
    while (t--)
    {
        // test input
        cin >> n;
        arr.resize(n);
        for (ll i = 0; i < n; i++)
            cin >> arr[i];

        // test solve
//        cout << arr << "\n\n";

        cout << solve(arr) << '\n';
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned ll

#define v vector
#define vll vector<ll>
#define vb vector<bool>

#define p pair
#define pll pair<ll, ll>

#define uset unordered_set
#define umap unordered_map
#define sll set<ll>
#define mpll map<ll, ll>

#define dqll deque<ll>
#define stll stack<ll>
#define qll queue<ll>

#define fi first
#define se second

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define all(x) (x).begin(), (x).end()

using namespace std;

// STRUCTS & CLASSES
///////////////////////////////////////////////////////////////////////////



// GLOBALS
///////////////////////////////////////////////////////////////////////////

ll n, t;
vll arr;

// HELPER FUNCS
///////////////////////////////////////////////////////////////////////////

vll diff(vll& arr)
{
    vll res(arr.size() - 1);
    for (ll i = 0; i < arr.size() - 1; i++)
    {
        res[i] = arr[i + 1] - arr[i];
    }
    return res;
}

ll sum(vll& arr)
{
    ll res = 0;
    for (auto i : arr)
    {
        res += i;
    }
    return res;
}

ll solve(vll& arr, ll depth = 0)
{
    if (arr.size() == 1)
    {
        return arr[0];
    }

    ll s = sum(arr);
    vll d = diff(arr);
    ll s1 = solve(d, depth + 1);

//    cout << d << '\n';
//    cout << s << ' ' << s1 << '\n';

    if (depth == 0)
    {
//        cout << max(s, abs(s1)) << '\n';
        return max(s, abs(s1));
    }
    else
    {
        return max(abs(s), abs(s1));
    }
}

// MAIN
///////////////////////////////////////////////////////////////////////////

int main()
{
    fastio;
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);

    // input
    cin >> t;

    // solve
    while (t--)
    {
        // test input
        cin >> n;
        arr.resize(n);
        for (ll i = 0; i < n; i++)
            cin >> arr[i];

        // test solve
//        cout << arr << "\n\n";

        cout << solve(arr) << '\n';
    }

    return 0;
}