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

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define MOD 1000000007
#define PLL pair<ll, ll>
#define PII pair<int, int>
#define PI acos(-1.0)
using namespace std;
const int N = 1e5 + 10;

int fastpow(int n, int x, int m){
 int ret = 1;
 n%=m;
 while(x){
  if(x&1) (ret*=n)%=m;
  x>>=1;
  (n*=n)%=m;
 }
 return ret;
}

int modInverse(int n , int m){
    return fastpow(n,m-2,m);
}

int ncrMod(int n , int r , int m){
    if (n < r)
        return 0;
    if (r == 0)
        return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % m;

    return (fac[n] * modInverse(fac[r], m) % m
            * modInverse(fac[n - r], m) % m)
           % m;
}

//********************************Solution starts here***********************************

void solve(){
    int n;
    cin >>n;
    int arr[n];
    for(int i=0 ; i<n ; i++) cin >> arr[i];

    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }

    if(n==2){
      if(arr[0]>0 && arr[1]>0)
        cout<<abs(arr[0])+abs(arr[1])<<endl;
      else
        cout << abs(arr[0]-arr[1])<<endl;
        return;
    }

    int final = n-1;
    int ans=0;
    for(int i=0 ; i<n ; i++){
        int sum = 0;
        for(int i=0 ; i<=final ; i++) sum+=arr[i];
        ans = max(ans,abs(sum));

        for(int i=0 ; i<final ; i++){
            arr[i]=arr[i+1]-arr[i];
        }
        final--;
    }

    cout << ans << endl;
}

signed main() {
    ios:: sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define MOD 1000000007
#define PLL pair<ll, ll>
#define PII pair<int, int>
#define PI acos(-1.0)
using namespace std;
const int N = 1e5 + 10;

int fastpow(int n, int x, int m){
 int ret = 1;
 n%=m;
 while(x){
  if(x&1) (ret*=n)%=m;
  x>>=1;
  (n*=n)%=m;
 }
 return ret;
}

int modInverse(int n , int m){
    return fastpow(n,m-2,m);
}

int ncrMod(int n , int r , int m){
    if (n < r)
        return 0;
    if (r == 0)
        return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % m;

    return (fac[n] * modInverse(fac[r], m) % m
            * modInverse(fac[n - r], m) % m)
           % m;
}

//********************************Solution starts here***********************************

void solve(){
    int n;
    cin >>n;
    int arr[n];
    for(int i=0 ; i<n ; i++) cin >> arr[i];

    if(n==1){
        cout<<arr[0]<<endl;
        return;
    }

    if(n==2){
      if(arr[0]>0 && arr[1]>0)
        cout<<abs(arr[0])+abs(arr[1])<<endl;
      else
        cout << abs(arr[0]-arr[1])<<endl;
        return;
    }

    int final = n-1;
    int ans=INT_MIN;
    for(int i=0 ; i<n ; i++){
        int sum = 0;
        for(int j=0 ; j<=final ; j++) sum+=arr[j];
        
        if(i==0) ans = max(ans,sum);
        else ans = max(ans,abs(sum));

        for(int i=0 ; i<final ; i++){
            arr[i]=arr[i+1]-arr[i];
        }
        final--;
    }

    cout << ans << endl;
  
}

signed main() {
    ios:: sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}