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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <climits>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
#define int long long
#define endl '\n'
#define fastio()ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
int mod1=998244353;
int mod2=1e9+9;
int Dp[12][1002][1002];
int Abs(int a,int b){
    if(a>b){
        return a-b;
    }
    return b-a;
}
void input(vector<int>& vec,int n){
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
}
void print(vector<int>& vec){
    for(auto it:vec){
    	cout<<it<<" ";
    }
    cout<<endl;
}
int Pow(int k,int n){
    if(n==0){
        return 1;
    }
    int temp=Pow(k,n/2)%mod1;
    if(n%2==0){
        return (temp*temp)%mod1;
    }
    else{
        return (((temp*temp)%mod1)*k)%mod1;
    }
}
 
int digits(int num){
    int ans=0;
    while(num){
        if(num%10==0){
            num=num/10;
            ans++;
        }
        else{
            break;
        }
    }
    return ans;
}
int digits2(int num){
    int ans=0;
    while(num){
        num=num/10;
        ans++;
    }
    return ans;
}
 
int query(int j){
    
    cout<<"? "<<1<<" "<<j<<endl;
    int ans=0;
    int x;
    cin>>x;
    return x;
}

class DisjointSet {
    vector<int> rank, parent, size;
public:
    DisjointSet(int n) {
        rank.resize(n + 1, 0);
        parent.resize(n + 1);
        size.resize(n + 1);
        for (int i = 0; i <= n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    int findUPar(int node) {
        if (node == parent[node])
            return node;
        return parent[node] = findUPar(parent[node]);
    }

    void unionByRank(int u, int v) {
        int ulp_u = findUPar(u);
        int ulp_v = findUPar(v);
        if (ulp_u == ulp_v) return;
        if (rank[ulp_u] < rank[ulp_v]) {
            parent[ulp_u] = ulp_v;
        }
        else if (rank[ulp_v] < rank[ulp_u]) {
            parent[ulp_v] = ulp_u;
        }
        else {
            parent[ulp_v] = ulp_u;
            rank[ulp_u]++;
        }
    }

    void unionBySize(int u, int v) {
        int ulp_u = findUPar(u);
        int ulp_v = findUPar(v);
        if (ulp_u == ulp_v) return;
        if (size[ulp_u] < size[ulp_v]) {
            parent[ulp_u] = ulp_v;
            size[ulp_v] += size[ulp_u];
        }
        else {
            parent[ulp_v] = ulp_u;
            size[ulp_u] += size[ulp_v];
        }
    }
};
int func1(vector<vector<int>> &vec,int n,int d,int a){
    queue<pair<int,int>> q;
    int minus=0;
    int ans=0;
    for(int i=0;i<n;i++){
        int currI=vec[i][0];
        int currH=vec[i][1];
        while(!q.empty()){
            auto [ele,m]=q.front();
            if(ele<currI){
                minus-=m;
                q.pop();
            }
            else{
                break;
            }
        }
        int diff=currH-minus;
        if(diff<0){
            diff=0;
        }
        int need=(diff+a-1)/a;
        ans+=need;
        minus+=need*a;
        q.push({currI+2*d,need*a});
    }
    return ans;
}
int func2(vector<vector<int>> &vec,int n,int d,int a){
    queue<pair<int,int>> q;
    int minus=0;
    int ans=0;
    for(int i=n-1;i>=0;i--){
        int currI=vec[i][0];
        int currH=vec[i][1];
        while(!q.empty()){
            auto [ele,m]=q.front();
            if(ele>currI){
                minus-=m;
                q.pop();
            }
            else{
                break;
            }
        }
        int diff=currH-minus;
        if(diff<0){
            diff=0;
        }
        int need=(diff+a-1)/a;
        ans+=need;
        minus+=need*a;
        q.push({currI-2*d,need*a});
    }
    return ans;
}
int gcd(int a,int b,int &x,int &y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,x2;
    int st= gcd(b%a,a,x1,x2);
    y=x1;
    x=x2-x1*(b/a);
    return st;
}
// int val=0;
void swap2(vector<int>& vec,int i,int j){
    if(i==j){
        return;
    }
    // val+=j-i+1;
    while(i<=j){
        swap(vec[i],vec[j]);
        i++;
        j--;
    }
}
bool check(int a,int k){
    while(a){
        int need;
        if(a%10<=7){
            need=7-a%10;
        }
        else{
             need=17-a%10;
        }
        if(need<=k){
            return true;
        }
        a/=10;
    }
    return false;
}
void solve() {
    int n;
    cin>>n;
    vector<int> vec(n);
    input(vec,n);
    if(n==1){
        cout<<vec[0]<<endl;
        return;
    }
    vector<int> New(n);
    int ans=0;
    for(auto it:vec){
        ans+=it;
    }
    for(int j=1;j<=n-1;j++){
        for(int i=0;i<n-j;i++){
            New[i]=(vec[i]-vec[i+1]);
        }
        swap(New,vec);
        int sum=0;
        for(int i=0;i<=n-j;i++){
            sum+=vec[i];
        }
        ans=max(ans,abs(sum));
    }
    cout<<max(ans,abs(vec[0]))<<endl;
}
signed main(){
    fastio();
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
// 

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <climits>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
#define int long long
#define endl '\n'
#define fastio()ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
int mod1=998244353;
int mod2=1e9+9;
int Dp[12][1002][1002];
int Abs(int a,int b){
    if(a>b){
        return a-b;
    }
    return b-a;
}
void input(vector<int>& vec,int n){
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
}
void print(vector<int>& vec){
    for(auto it:vec){
    	cout<<it<<" ";
    }
    cout<<endl;
}
int Pow(int k,int n){
    if(n==0){
        return 1;
    }
    int temp=Pow(k,n/2)%mod1;
    if(n%2==0){
        return (temp*temp)%mod1;
    }
    else{
        return (((temp*temp)%mod1)*k)%mod1;
    }
}
 
int digits(int num){
    int ans=0;
    while(num){
        if(num%10==0){
            num=num/10;
            ans++;
        }
        else{
            break;
        }
    }
    return ans;
}
int digits2(int num){
    int ans=0;
    while(num){
        num=num/10;
        ans++;
    }
    return ans;
}
 
int query(int j){
    
    cout<<"? "<<1<<" "<<j<<endl;
    int ans=0;
    int x;
    cin>>x;
    return x;
}

class DisjointSet {
    vector<int> rank, parent, size;
public:
    DisjointSet(int n) {
        rank.resize(n + 1, 0);
        parent.resize(n + 1);
        size.resize(n + 1);
        for (int i = 0; i <= n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    int findUPar(int node) {
        if (node == parent[node])
            return node;
        return parent[node] = findUPar(parent[node]);
    }

    void unionByRank(int u, int v) {
        int ulp_u = findUPar(u);
        int ulp_v = findUPar(v);
        if (ulp_u == ulp_v) return;
        if (rank[ulp_u] < rank[ulp_v]) {
            parent[ulp_u] = ulp_v;
        }
        else if (rank[ulp_v] < rank[ulp_u]) {
            parent[ulp_v] = ulp_u;
        }
        else {
            parent[ulp_v] = ulp_u;
            rank[ulp_u]++;
        }
    }

    void unionBySize(int u, int v) {
        int ulp_u = findUPar(u);
        int ulp_v = findUPar(v);
        if (ulp_u == ulp_v) return;
        if (size[ulp_u] < size[ulp_v]) {
            parent[ulp_u] = ulp_v;
            size[ulp_v] += size[ulp_u];
        }
        else {
            parent[ulp_v] = ulp_u;
            size[ulp_u] += size[ulp_v];
        }
    }
};
int func1(vector<vector<int>> &vec,int n,int d,int a){
    queue<pair<int,int>> q;
    int minus=0;
    int ans=0;
    for(int i=0;i<n;i++){
        int currI=vec[i][0];
        int currH=vec[i][1];
        while(!q.empty()){
            auto [ele,m]=q.front();
            if(ele<currI){
                minus-=m;
                q.pop();
            }
            else{
                break;
            }
        }
        int diff=currH-minus;
        if(diff<0){
            diff=0;
        }
        int need=(diff+a-1)/a;
        ans+=need;
        minus+=need*a;
        q.push({currI+2*d,need*a});
    }
    return ans;
}
int func2(vector<vector<int>> &vec,int n,int d,int a){
    queue<pair<int,int>> q;
    int minus=0;
    int ans=0;
    for(int i=n-1;i>=0;i--){
        int currI=vec[i][0];
        int currH=vec[i][1];
        while(!q.empty()){
            auto [ele,m]=q.front();
            if(ele>currI){
                minus-=m;
                q.pop();
            }
            else{
                break;
            }
        }
        int diff=currH-minus;
        if(diff<0){
            diff=0;
        }
        int need=(diff+a-1)/a;
        ans+=need;
        minus+=need*a;
        q.push({currI-2*d,need*a});
    }
    return ans;
}
int gcd(int a,int b,int &x,int &y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,x2;
    int st= gcd(b%a,a,x1,x2);
    y=x1;
    x=x2-x1*(b/a);
    return st;
}
// int val=0;
void swap2(vector<int>& vec,int i,int j){
    if(i==j){
        return;
    }
    // val+=j-i+1;
    while(i<=j){
        swap(vec[i],vec[j]);
        i++;
        j--;
    }
}
bool check(int a,int k){
    while(a){
        int need;
        if(a%10<=7){
            need=7-a%10;
        }
        else{
             need=17-a%10;
        }
        if(need<=k){
            return true;
        }
        a/=10;
    }
    return false;
}
void solve() {
    int n;
    cin>>n;
    vector<int> vec(n);
    input(vec,n);
    if(n==1){
        cout<<vec[0]<<endl;
        return;
    }
    vector<int> New(n);
    int ans=0;
    for(auto it:vec){
        ans+=it;
    }
    for(int j=1;j<=n-1;j++){
        for(int i=0;i<n-j;i++){
            New[i]=(vec[i]-vec[i+1]);
        }
        swap(New,vec);
        int sum=0;
        for(int i=0;i<n-j;i++){
            sum+=vec[i];
        }
        ans=max(ans,abs(sum));
    }
    cout<<max(ans,vec[0])<<endl;
}
signed main(){
    fastio();
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
//