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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin >> t;
    while (t--)
    {
        long long int n;
        cin >> n;
        vector<long long int> v(n);
        long long int initialsum = 0;
        for (long long int i = 0; i < n; i++)
        {
            cin >> v[i];
            initialsum += v[i];
        }
        long long int final = 0;
        while (v.size() > 1)
        {
            vector<long long int> w = v;
            reverse(w.begin(), w.end());
            long long int firstsum = 0, secondsum = 0, currsum = 0, curr1sum = 0;

            for (long long int i = 1; i < v.size(); i++)
            {
                firstsum += (v[i] - v[i - 1]);
            }

            for (long long int i = 1; i < w.size(); i++)
            {
                secondsum += (w[i] - w[i - 1]);
            }
            for (long long int i = 0; i < v.size(); i++)
            {
                currsum += v[i];
            }
            for (long long int i = 0; i < w.size(); i++)
            {
                curr1sum += w[i];
            }
            if (currsum > curr1sum && currsum > firstsum && currsum > secondsum)
            {
                final = currsum;
                break;
            }
            else if (curr1sum > currsum && curr1sum > firstsum && curr1sum > secondsum)
            {
                final = curr1sum;
                break;
            }
            vector<long long int> newarray;

            if (firstsum > secondsum)
            {

                for (long long int i = 1; i < v.size(); i++)
                {
                    newarray.push_back(v[i] - v[i - 1]);
                }
            }
            else
            {

                for (long long int i = 1; i < w.size(); i++)
                {
                    newarray.push_back(w[i] - w[i - 1]);
                }
            }

            v = newarray;
        }
        if (n == 1)
        {
            cout << v[0] << endl;
        }
        else
        {
            cout << max(v[0], max(initialsum, final)) << endl;
        }
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin >> t;
    while (t--)
    {
        long long int n;
        cin >> n;
        vector<long long int> v(n);
        long long int initialsum = 0;
        for (long long int i = 0; i < n; i++)
        {
            cin >> v[i];
            initialsum += v[i];
        }

        while (v.size() > 1)
        {
            vector<long long int> w = v;
            reverse(w.begin(), w.end());
            long long int firstsum = 0, secondsum = 0;

            for (long long int i = 1; i < v.size(); i++)
            {
                firstsum += (v[i] - v[i - 1]);
            }

            for (long long int i = 1; i < w.size(); i++)
            {
                secondsum += (w[i] - w[i - 1]);
            }

            vector<long long int> newarray;
            if (firstsum > secondsum)
            {

                for (long long int i = 1; i < v.size(); i++)
                {
                    newarray.push_back(v[i] - v[i - 1]);
                }
            }
            else
            {

                for (long long int i = 1; i < w.size(); i++)
                {
                    newarray.push_back(w[i] - w[i - 1]);
                }
            }
            initialsum = max(initialsum, max(firstsum, secondsum));
            v = newarray;
        }

        cout << initialsum << endl;
    }
    return 0;
}