Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 5):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define sll set<ll>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
const ll mod = 1e9 + 7;
const ll M = 2 * 1e5 + 1;
using namespace std;

ll mod_exp(ll base, ll exp, ll mod)
{
    ll result = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
        {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

ll inv(ll a, ll b)
{
    return 1 < a ? b - inv(b % a, a) * b / a : 1LL;
}

ll factorial[M + 1];

ll ncr(ll n, ll r)
{
    if (r == 0)
        return 1;
    if (r > n)
        return 0;
    ll ans = factorial[n] * inv((factorial[r] * factorial[n - r]) % mod, mod);
    return (ans % mod);
}

vll primeFactors(ll n)
{
    vll v;
    while (n % 2 == 0)
    {
        v.pb(2);
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.pb(i);
            n = n / i;
        }
    }
    if (n > 2)
        v.pb(n);
    return v;
}

// Every even natural number less than 4*1e18 can be represented as sum of 2 primes

sll allFactors(ll n)
{
    sll st;
    for (ll i = 1; i <= sqrtl(n); i++)
    {
        if (n % i == 0)
        {
            st.insert(i);
            st.insert(n / i);
        }
    }
    return st;
}

vll SieveOfEratosthenes(ll n)
{
    vll v;
    vector<bool> prime(n + 1, true);
    for (ll p = 2; p * p <= n; p++)
        if (prime[p] == true)
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
    for (ll p = 2; p <= n; p++)
        if (prime[p])
            v.pb(p);
    return v;
}

int binarysearch(int arr[],int n,int k){
    int s = 0, e = n - 1; // Search range from 0 to n-1
    while (s <= e) // Loop until the search space is valid
    {
        int mid = (s + e) / 2; // Find the middle element
        if (arr[mid] == k) // If the middle element is the target, return the index
            return mid;
        else if (arr[mid] < k) // If target is greater, move the left pointer to mid+1
            s = mid + 1;
        else // If target is smaller, move the right pointer to mid-1
            e = mid - 1;
    }
    return -1; // If the element is not found, return -1
}
int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        ll arr[n],sum=0;
        for(int i=0;i<n;i++){
            cin >> arr[i];
            sum+=arr[i];
        }
        if(n==1){
            cout<<arr[0]<<endl;
        }
        else{
            ll z=1;ll mx;
            if(arr[0]==arr[n-1]){mx=sum;}
            else{mx=abs(sum);}
            while(z){
                if(n==1){cout<<mx<<endl;z=0;}
                else{
                    ll sum=0;
                    if(arr[0]==arr[n-1]){
                        for(int i=0;i<n-1;i++){
                            sum+=(arr[i+1]-arr[i]);
                            arr[i]=(arr[i+1]-arr[i]);
                        }
                        mx=max(mx,(sum));
                    }
                    else{
                        for(int i=0;i<n-1;i++){
                            sum+=(arr[i+1]-arr[i]);
                            arr[i]=(arr[i+1]-arr[i]);
                        }
                        mx=max(mx,abs(sum));
                    }
                    n=n-1;
                }
            }
        }
    }
}




Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define sll set<ll>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
const ll mod = 1e9 + 7;
const ll M = 2 * 1e5 + 1;
using namespace std;

ll mod_exp(ll base, ll exp, ll mod)
{
    ll result = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
        {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

ll inv(ll a, ll b)
{
    return 1 < a ? b - inv(b % a, a) * b / a : 1LL;
}

ll factorial[M + 1];

ll ncr(ll n, ll r)
{
    if (r == 0)
        return 1;
    if (r > n)
        return 0;
    ll ans = factorial[n] * inv((factorial[r] * factorial[n - r]) % mod, mod);
    return (ans % mod);
}

vll primeFactors(ll n)
{
    vll v;
    while (n % 2 == 0)
    {
        v.pb(2);
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.pb(i);
            n = n / i;
        }
    }
    if (n > 2)
        v.pb(n);
    return v;
}

// Every even natural number less than 4*1e18 can be represented as sum of 2 primes

sll allFactors(ll n)
{
    sll st;
    for (ll i = 1; i <= sqrtl(n); i++)
    {
        if (n % i == 0)
        {
            st.insert(i);
            st.insert(n / i);
        }
    }
    return st;
}

vll SieveOfEratosthenes(ll n)
{
    vll v;
    vector<bool> prime(n + 1, true);
    for (ll p = 2; p * p <= n; p++)
        if (prime[p] == true)
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
    for (ll p = 2; p <= n; p++)
        if (prime[p])
            v.pb(p);
    return v;
}

int binarysearch(int arr[],int n,int k){
    int s = 0, e = n - 1; // Search range from 0 to n-1
    while (s <= e) // Loop until the search space is valid
    {
        int mid = (s + e) / 2; // Find the middle element
        if (arr[mid] == k) // If the middle element is the target, return the index
            return mid;
        else if (arr[mid] < k) // If target is greater, move the left pointer to mid+1
            s = mid + 1;
        else // If target is smaller, move the right pointer to mid-1
            e = mid - 1;
    }
    return -1; // If the element is not found, return -1
}
int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        ll arr[n],sum=0;
        for(int i=0;i<n;i++){
            cin >> arr[i];
            sum+=arr[i];
        }
        if(n==1){
            cout<<arr[0]<<endl;
        }
        //n=2,3,4....
        else{
            ll z=1;ll mx;
            if(arr[0]==arr[n-1]){mx=sum;}
            // else{mx=abs(sum);}
            while(z){
                if(n==1){cout<<mx<<endl;z=0;}
                else{
                    ll sum=0;
                    if(arr[0]==arr[n-1]){
                        for(int i=0;i<n-1;i++){
                            sum+=(arr[i+1]-arr[i]);
                            arr[i]=(arr[i+1]-arr[i]);
                        }
                        mx=max(mx,(sum));
                    }
                    else{
                        for(int i=0;i<n-1;i++){
                            sum+=(arr[i+1]-arr[i]);
                            arr[i]=(arr[i+1]-arr[i]);
                        }
                        mx=max(mx,abs(sum));
                    }
                    n=n-1;
                }
            }
        }
    }
}