    //#define MYDEBUG
    #ifndef oUwUo
    	#include <bits/stdc++.h>

    	using namespace std;

    	#define endl << "\n"
    	#define FOR(x, n) for (int x=0; x < n; x++)
    	#define ll long long
    	#define vi vector<int>
    	#define vpi vector<pair<int,int>>
    	#define vvi vector<vector<i>>
    	#define vll vector<ll>
    	#define vpll vector<pair<ll,ll>>
    	#define vvll vector<vector<ll,ll>>
    	#define mp make_pair
    	#define SMIN(x,y) x=min(x,y)
    	#define SMAX(x,y) x=max(x,y)
    	#define RNG(j,l,r) for(int j=l;j<r;j++)
    	#define REVRNG(j,l,r) for(int j=r-1;j>=l;j--)

    	#ifdef MYDEBUG
    	#define D(x) {cerr << #x << " = " << x endl;}
    	#define D2(x, y) {cerr << #x << " = " << x << "/t" << #y << " = " << y endl;}
    	#define DT(t,x) {cerr<<t<<"\t"<<#x<<" = "<<x endl;}
    	#define DIT(cont) {cerr<<"container: " <<#cont endl<<"\t"; for(auto x: cont){cerr<<x<<" ";} cerr endl;}
    	#define DITlmd(cont,lmd) {cerr<<"container: " <<#cont endl<<"\t"; for(auto x: cont){cerr<<lmd(x)<<" ";} cerr endl;}
    	#define DARR(arr,n) {cerr<<"array :"<<#arr endl <<"\t" ; FOR(i,n){cerr<<arr[i]<<" ";} cerr endl;}
    	#define DARRlmd(arr,n,lmd) {cerr<<"array :"<<#arr endl <<"\t" ; FOR(i,n){cerr<<lmd(arr[i])<<" ";} cerr endl;}
    	#define TT(tex) cerr<<tex endl;
    	#else
    	#define D(x)
    	#define D2(x, y)
    	#define DT(t,x)
    	#define DIT(cont)
    	#define DITlmd(cont,lmd)
    	#define DARR(arr,n)
    	#define DARRlmd(arr,n,lmd)
    	#define TT(tex)
    	#endif
    #endif

    void solve()
    {
    	// code
		int n; cin>>n;

		ll res=0;

		vll a(n),b(n-1);

		FOR(i,n) cin>>a[i];

		for(int el:a) res+=el;

		while(a.size()>1){
			int s=a.size();
			b.resize(s-1);
			ll value=0;

			FOR(i,s-1){
				b[i]=a[i]-a[i+1];
			}
			for(ll el :b) value+=el;
			res=max(res,abs(value));

			swap(a,b);

		}

		cout<<res endl;

    	return;
    }

    int main()
    {
        cin.tie(0);
        cout.sync_with_stdio(0);
    	int _;
    	cin >> _;
    	for (int t = 1; t <= _; t++)
    	{
    		#ifdef MYDEBUG
    			cerr << "______________________ testcsase = " << t endl;
    		#endif
    		solve();
    	}

    	return 0;
    }

    //#define MYDEBUG
    #ifndef oUwUo
    	#include <bits/stdc++.h>

    	using namespace std;

    	#define endl << "\n"
    	#define FOR(x, n) for (int x=0; x < n; x++)
    	#define ll long long
    	#define vi vector<int>
    	#define vpi vector<pair<int,int>>
    	#define vvi vector<vector<i>>
    	#define vll vector<ll>
    	#define vpll vector<pair<ll,ll>>
    	#define vvll vector<vector<ll,ll>>
    	#define mp make_pair
    	#define SMIN(x,y) x=min(x,y)
    	#define SMAX(x,y) x=max(x,y)
    	#define RNG(j,l,r) for(int j=l;j<r;j++)
    	#define REVRNG(j,l,r) for(int j=r-1;j>=l;j--)

    	#ifdef MYDEBUG
    	#define D(x) {cerr << #x << " = " << x endl;}
    	#define D2(x, y) {cerr << #x << " = " << x << "/t" << #y << " = " << y endl;}
    	#define DT(t,x) {cerr<<t<<"\t"<<#x<<" = "<<x endl;}
    	#define DIT(cont) {cerr<<"container: " <<#cont endl<<"\t"; for(auto x: cont){cerr<<x<<" ";} cerr endl;}
    	#define DITlmd(cont,lmd) {cerr<<"container: " <<#cont endl<<"\t"; for(auto x: cont){cerr<<lmd(x)<<" ";} cerr endl;}
    	#define DARR(arr,n) {cerr<<"array :"<<#arr endl <<"\t" ; FOR(i,n){cerr<<arr[i]<<" ";} cerr endl;}
    	#define DARRlmd(arr,n,lmd) {cerr<<"array :"<<#arr endl <<"\t" ; FOR(i,n){cerr<<lmd(arr[i])<<" ";} cerr endl;}
    	#define TT(tex) cerr<<tex endl;
    	#else
    	#define D(x)
    	#define D2(x, y)
    	#define DT(t,x)
    	#define DIT(cont)
    	#define DITlmd(cont,lmd)
    	#define DARR(arr,n)
    	#define DARRlmd(arr,n,lmd)
    	#define TT(tex)
    	#endif
    #endif

    void solve()
    {
    	// code
		int n; cin>>n;

		ll res=0;

		vi a(n),b(n-1);

		FOR(i,n) cin>>a[i];

		for(int el:a) res+=el;

		while(a.size()>1){
			int s=a.size();
			b.resize(s-1);
			ll value=0;

			FOR(i,s-1){
				b[i]=a[i]-a[i+1];
			}
			for(int el :b) value+=el;
			res=max(res,abs(value));

			swap(a,b);

		}

		cout<<res endl;

    	return;
    }

    int main()
    {
        cin.tie(0);
        cout.sync_with_stdio(0);
    	int _;
    	cin >> _;
    	for (int t = 1; t <= _; t++)
    	{
    		#ifdef MYDEBUG
    			cerr << "______________________ testcsase = " << t endl;
    		#endif
    		solve();
    	}

    	return 0;
    }

Answer: 1


#include <bits/stdc++.h>
using namespace std;
/*
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) (1<<lround(log2(S)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
*/
#define pb push_back
#define sqr(x) ((x) * (x))
#define gcd(a,b) __gcd(a,b)
#define FAST_IO ios::sync_with_stdio(0);cin.tie(0);
#define MOD 1000000007
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rep0(i,n) for(int i = 0; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define int_max INT_MAX
#define int_min INT_MIN
#define endl "\n"
#define LSOne(S) ((S) & (-S))
#define ceros(v) __builtin_ctzll(v)
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n";
typedef  long long ll;
typedef pair<int,int> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef tuple <int,string,string> iss;
typedef tuple <int,int,int> iii;
#pragma GCC optimize("Ofast,unroll-loops,fast-math,prefetch-loop-arrays,tree-vectorize,omit-frame-pointer,no-peephole")
//mt19937_64 qrand(chrono::steady_clock::now().time_since_epoch().count());

main() {
    FAST_IO;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int tt;
    cin >> tt;
    while(tt -- ){
        int n;
        cin >> n;
        vector<ll> datos(n);
        for(ll &i:datos) cin >> i;
        int newN=n;
        ll ans=-1e18;
        for(int i=0;i<n;i++){
            ll sum=0;
            for(int i=0;i<newN;i++)sum += datos[i];
            if(i==0){
                ans = max(ans, sum);
            }else{
                ans = max(ans, max(sum, - sum));
            }
            newN--;
            for(int i=0;i<newN;i++){
                datos[i]=datos[i+1]-datos[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
/*
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) (1<<lround(log2(S)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
*/
#define pb push_back
#define sqr(x) ((x) * (x))
#define gcd(a,b) __gcd(a,b)
#define FAST_IO ios::sync_with_stdio(0);cin.tie(0);
#define MOD 1000000007
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rep0(i,n) for(int i = 0; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define int_max INT_MAX
#define int_min INT_MIN
#define endl "\n"
#define LSOne(S) ((S) & (-S))
#define ceros(v) __builtin_ctzll(v)
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n";
typedef  long long ll;
typedef pair<int,int> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef tuple <int,string,string> iss;
typedef tuple <int,int,int> iii;
#pragma GCC optimize("Ofast,unroll-loops,fast-math,prefetch-loop-arrays,tree-vectorize,omit-frame-pointer,no-peephole")
//mt19937_64 qrand(chrono::steady_clock::now().time_since_epoch().count());

main() {
    FAST_IO;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int tt;
    cin >> tt;
    while(tt -- ){
        int n;
        cin >> n;
        vector<ll> datos(n);
        for(ll &i:datos) cin >> i;
        int newN=n;
        ll ans=-1e18;
        for(int i=0;i<n;i++){
            ll sum=0;
            for(int i=0;i<newN;i++)sum += datos[i];
            if(i==0){
                ans = max(ans, sum);
                cout << 'a';
            }else{
                ans = max(ans, max(sum, - sum));
            }
            newN--;
            for(int i=0;i<newN;i++){
                datos[i]=datos[i+1]-datos[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
#define TC int t;cin>>t;while(t--)
#define Tanveer ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
#ifdef LOKAL
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define int long long

void solve()
{
    int n; cin>>n;
    vector<int> v(n);
    int ans = 0;
    for(int i=0;i<n; i++) cin>>v[i], ans+=v[i];

    vector<int> t;
    while(v.size()!=1)
    {
        for(int i=1; i<v.size(); i++) t.push_back(v[i]-v[i-1]);
        v = t;
        int sum = 0;
        for(int i=0;i<t.size(); i++){
            sum+=(v[i]);
        }
        ans = max(ans, abs(sum));
        t.clear();

    }
    cout<<ans<<endl;
}
int32_t main()
{
    #ifndef LOKAL
    Tanveer
    #endif
    TC
    solve();
    return 0;
}

#include<bits/stdc++.h>
#define TC int t;cin>>t;while(t--)
#define Tanveer ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
#ifdef LOKAL
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define int long long
int ans;
void fun(vector<int> v)
{
    if(v.size()==1){
        ans = max(ans, v[0]); return;
    }
    int n = v.size();
    vector<int> t;
    for(int i=1; i<n; i++) t.push_back(v[i]-v[i-1]);
    fun(t);
    reverse(v.begin(), v.end());
    vector<int> tt;
    for(int i=1; i<n; i++) tt.push_back(v[i]-v[i-1]);
    fun(tt);
}
void solve()
{
    int n; cin>>n;
    vector<int> v(n);
    ans = 0;
    for(int i=0;i<n; i++) cin>>v[i], ans+=v[i];
    fun(v);
    cout<<ans<<endl;
}
int32_t main()
{
    #ifndef LOKAL
    Tanveer
    #endif
    TC
    solve();
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int n, t;

void solve() {
    scanf("%d", &n);
    long long a[n];

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lli", a + i);
        ans += a[i];
    }

    for (int i = 1; i < n; i++) {
        long long curr = 0;
        for (int j = n - 1; j >= i; j--) {
            a[j] -= a[j - 1];
            curr += a[j];
        }
        ans = max(ans, abs(curr));
    }

    printf("%lli\n", ans);
}

int main() {
    scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int n, t;

void solve() {
    scanf("%d", &n);
    int a[n], ans = 0;

    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        ans += a[i];
    }

    for (int i = 1; i < n; i++) {
        int curr = 0;
        for (int j = n - 1; j >= i; j--) {
            a[j] -= a[j - 1];
            curr += a[j];
        }
        ans = max(ans, abs(curr));
    }

    printf("%d\n", ans);
}

int main() {
    scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Answer: 1


#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

ll min(ll a, ll b){
	if (a<b)return a;
	return b;
}

ll max(ll a, ll b){
	if (a>b)return a;
	return b;
}

void solve(){
	ll n ; cin >> n;
	vl arr(n);
	ll sum =0;
	for (int i=0;i<n;i++){cin>>arr[i];sum+=arr[i];}
	if (n==1){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		ll s =0;
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
			s+=arr[j];
		}
		sum = max(abs(s),sum);
	}
	cout <<sum<<endl;
}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}

#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();
#include<bits/stdc++.h>
#define ll long long
#define read(x) int x;cin>>x;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vb vector<bool>
#define ld long double
#define vld vector<ld>
using namespace std;

void init_code(){
	#ifndef ONLINE_JUDGE
	freopen("inputf.txt","r",stdin);
	freopen("outputf.txt","w",stdout);
	#endif
}

int solve2(int pos, vvl &edges,int n){
	int maxi = INT_MIN;
	for (int i=0;i<n;i++){
		if (i == pos)continue;
		bool p = false;
		for (int j=0;j<edges[i].size();j++){
			if (pos == edges[i][j]){
				p = true;
				break;
			}
		}
		int sz = edges[i].size()-p;
		maxi = max(maxi,sz);
	}

	return maxi ;
}

ld max(ld a , ld b){
	if (a>b)return a;
	return b;
}

void solve(){
	ld n; cin >>n;
	ld sum =0;
	vld arr(n);
	for (int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if (n==1 and arr[0] < 0){
		cout <<arr[0]<<endl;
		return ;
	}
	for (int i=0;i<n-1;i++){
		for (int j=0;j<n-1-i;j++){
			arr[j] = arr[j]-arr[j+1];
		}
	}
	cout <<max(sum,abs(arr[0]))<<endl;

}

int main(){
	fast ;
	read(t);
	while (t--)solve();
	return 0;
}

Answer: 1


//Bharti Nema
#include<bits/stdc++.h>
using namespace std;
bool isValid(int,int);
int n,m;
int main() {
	int t;
	cin>>t;
	while(t--) {
		long long int n,baari=0,ans=0,sum1=0,sum2=0;
		cin>>n;
		long long int a[n+1],b[n+1];
		for(int i=0;i<n;i++)
			cin>>a[i];

		for(int i=0;i<n;i++) {
			ans+=a[i];
		}
		if(n==1) {
			cout<<a[0]<<endl;
			continue;
		}
		while(n>1) {
			for(int i=0;i<n-1;i++) {
				a[i]=a[i]-a[i+1];
			}
			n-=1;
		}

		cout<<max(ans,abs(a[0]))<<endl;

		// while(n>1) {
		// for(int i=1,j=0;i<n && j<n-1;i++,j++) {

		// }
	// 		sum1+=(a[i]-a[i-1]);
	// 		sum2+=(a[j]-a[j+1]);
	// 	}
	// 	if(sum1>sum2) {
	// 		ans=max(ans,sum1);
	// 		for(int i=1;i<n;i++) {
	// 			if(baari==0)
	// 			    b[i-1]=a[i]-a[i-1];
	// 		    else
	// 		        a[i-1]=b[i]-b[i-1];
	// 		}
	// 		n-=1;
	// 		if(baari==0)
	// 			baari=1;
	// 		else
	// 			baari=0;
	// 	}
	// 	else {
	// 		ans=max(ans,sum2);
	// 		for(int i=0,kahan=n-2;i<n-1;i++,kahan--) {
	// 			if(baari==0)
	// 			    b[kahan]=a[i]-a[i+1];
	// 		    else
	// 		    	a[kahan]=b[i]-b[i+1];
	// 		}
	// 		n-=1;
	// 		if(baari==0)
	// 			baari=1;
	// 		else
	// 			baari=0;
	// 	}
	// }

	// 	if(baari==0)
	// 		cout<<max(ans,a[0]);
	// 	else
	// 		cout<<max(ans,b[0]);
	}
}

//Bharti Nema
#include<bits/stdc++.h>
using namespace std;
bool isValid(int,int);
int n,m;
int main() {
	int t;
	cin>>t;
	while(t--) {
		long long int n,baari=0,ans=0,sum=0,sum2=0;
		cin>>n;
		long long int a[n+1],b[n+1];
		for(int i=0;i<n;i++)
			cin>>a[i];

		for(int i=0;i<n;i++) {
			ans+=a[i];
		}
		if(n==1) {
			cout<<a[0]<<endl;
			continue;
		}
		while(n>1) {
			for(int i=0;i<n-1;i++) {
				a[i]=a[i]-a[i+1];
			}
			n-=1;
			for(int i=0;i<n;i++) {
				sum+=a[i];
			}
			ans=max(ans,sum);
			sum=0;
			for(int i=0;i<n;i++) {
				sum+=(-a[i]);
			}
			ans=max(ans,sum);
			sum=0;
		}

		cout<<max(ans,abs(a[0]))<<endl;

		// while(n>1) {
		// for(int i=1,j=0;i<n && j<n-1;i++,j++) {

		// }
	// 		sum1+=(a[i]-a[i-1]);
	// 		sum2+=(a[j]-a[j+1]);
	// 	}
	// 	if(sum1>sum2) {
	// 		ans=max(ans,sum1);
	// 		for(int i=1;i<n;i++) {
	// 			if(baari==0)
	// 			    b[i-1]=a[i]-a[i-1];
	// 		    else
	// 		        a[i-1]=b[i]-b[i-1];
	// 		}
	// 		n-=1;
	// 		if(baari==0)
	// 			baari=1;
	// 		else
	// 			baari=0;
	// 	}
	// 	else {
	// 		ans=max(ans,sum2);
	// 		for(int i=0,kahan=n-2;i<n-1;i++,kahan--) {
	// 			if(baari==0)
	// 			    b[kahan]=a[i]-a[i+1];
	// 		    else
	// 		    	a[kahan]=b[i]-b[i+1];
	// 		}
	// 		n-=1;
	// 		if(baari==0)
	// 			baari=1;
	// 		else
	// 			baari=0;
	// 	}
	// }

	// 	if(baari==0)
	// 		cout<<max(ans,a[0]);
	// 	else
	// 		cout<<max(ans,b[0]);
	}
}

Answer: 2


//
// Created by Mrlaolu on 2024/7/10.
//

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include <format>

#define int long long
#define endl '\n'
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define x first
#define y second
#define lc v<<1
#define rc v<<1|1
const int N = 4e5 + 10;
using namespace std;
using PII = pair<int,int>;
using i128 = __int128;
#define debug0
const int base = 233;
const int ubase = 141;
using ull = unsigned long long;
const int MOD = 998244353;

int ans = -INT_MAX;
void dfs(vector<int>& arr,int sum){
    if(arr.size() == 1){
        return;
    }
    for(int k = 0;k <= 1;++k){
        if(k)reverse(arr.begin(),arr.end());
        int tsum = sum;
        vector<int>b;
        for(int i = 1;i < arr.size();++i){
            int t = arr[i] - arr[i - 1];
            tsum += t;
            b.push_back(t);
        }
        if(ans < (int)accumulate(b.begin(),b.end(),0)){
            ans = (int)accumulate(b.begin(),b.end(),0);
            for(auto it : b)cout << it << " ";
            cout << "ans :" << ans << endl;
        }

        dfs(b,0);
    }

};

void solve() {
    int n;cin >> n;
    vector<int>a(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    int ans = accumulate(a.begin(),a.end(),0);
    auto diff = [&](int x,int y){
        return x > 0 && y < 0 || x < 0 && y > 0;
    };
    while(a.size() > 1){
        vector<int>b;int cntb = 0,absb = 0,sumb = 0;
        for(int i = 1;i < a.size();++i){
            b.push_back(a[i]-a[i-1]);
            if(i > 1 && diff(b[i-1],b[i-2]))cntb++;
            absb += abs(b[i-1]);
            sumb += b[i-1];
        }
        reverse(a.begin(),a.end());
        vector<int>c;int cntc = 0,absc = 0,sumc = 0;
        for(int i = 1;i < a.size();++i){
            c.push_back(a[i]-a[i-1]);
            if(i > 1 && diff(c[i-1],c[i-2]))cntc++;
            absc += abs(c[i-1]);
            sumc += c[i - 1];
        }
        ans = max({ans,sumb,sumc});
        if(cntb == cntc){
            if(absb < absc)a = c;
            else a = c;
        }else{
            if(cntb > cntc)a = b;
            else a = c;
        }
    }

    cout << ans << endl;
}

#define FILE
#define MULTI

signed main() {

#ifndef ONLINE_JUDGE
#ifdef FILE
    freopen("in.txt", "r",stdin);
    freopen("out.txt", "w",stdout);
#endif
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;

#ifdef MULTI
    cin >> T;
#endif

    auto be = chrono::steady_clock::now();
    while(T--){
        solve();
    }

    auto af = chrono::steady_clock::now();
//    cout << chrono::duration<double,milli>(af-be).count() << "ms" << endl;
    return 0;
}

//
// Created by Mrlaolu on 2024/7/10.
//

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include <format>

#define int long long
#define endl '\n'
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define x first
#define y second
#define lc v<<1
#define rc v<<1|1
const int N = 4e5 + 10;
using namespace std;
using PII = pair<int,int>;
using i128 = __int128;
#define debug0
const int base = 233;
const int ubase = 141;
using ull = unsigned long long;
const int MOD = 998244353;

int ans = -INT_MAX;
void dfs(vector<int>& arr,int sum){
    if(arr.size() == 1){
        return;
    }
    for(int k = 0;k <= 1;++k){
        if(k)reverse(arr.begin(),arr.end());
        int tsum = sum;
        vector<int>b;
        for(int i = 1;i < arr.size();++i){
            int t = arr[i] - arr[i - 1];
            tsum += t;
            b.push_back(t);
        }
        ans = max(ans, (int)accumulate(b.begin(),b.end(),0));
        dfs(b,0);
    }
};

void solve() {
    int n;cin >> n;
    vector<int>a(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    ans = accumulate(a.begin(),a.end(),0);
    dfs(a,0);

    cout << ans << endl;
}

#define FILE
#define MULTI

signed main() {

#ifndef ONLINE_JUDGE
#ifdef FILE
    freopen("in.txt", "r",stdin);
    freopen("out.txt", "w",stdout);
#endif
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;

#ifdef MULTI
    cin >> T;
#endif

    auto be = chrono::steady_clock::now();
    while(T--){
        solve();
    }

    auto af = chrono::steady_clock::now();
//    cout << chrono::duration<double,milli>(af-be).count() << "ms" << endl;
    return 0;
}

Answer: 1


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cmath>
#include <queue>
#include <tuple>
using namespace std;

vector<int> diff(vector<int> arr){
    vector<int> ans(arr.size() - 1);
    for (int i = 0; i < ans.size(); i++){
        ans[i] = arr[i+1] - arr[i];
    }
    return ans;
}
void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    long long ans = 0;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
        ans += arr[i];
    }
    for (int i = 0; i < n - 1; i++){
        ans = max(ans, 1LL * abs(arr[arr.size() - 1] - arr[0]));
        arr = diff(arr);
    }
    cout << ans << "\n";
}

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; i++){
        solve();
    }
    return 0;

}

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cmath>
#include <queue>
#include <tuple>
using namespace std;

vector<long long> diff(vector<long long> arr){
    vector<long long> ans(arr.size() - 1);
    for (int i = 0; i < ans.size(); i++){
        ans[i] = arr[i+1] - arr[i];
    }
    return ans;
}
void solve(){
    int n;
    cin >> n;
    vector<long long> arr(n);
    long long ans = 0;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
        ans += arr[i];
    }
    for (int i = 0; i < n - 1; i++){
        ans = max(ans, 1LL * abs(arr[arr.size() - 1] - arr[0]));
        arr = diff(arr);
    }
    cout << ans << "\n";
}

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; i++){
        solve();
    }
    return 0;

}

Answer: 2


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <bits/stdc++.h>
#include <bitset>
#include <cstdio>
#include <cctype>
#define ll long long
#define all(vc) vc.begin() , vc.end()
#define inf  0x3f3f3f3f3f3f3f3f
#define N 1000005
#define khatun ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Time   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
using namespace std;
const ll mod = 1e9+7, infinity = 1e4;

vector<pair<int, int>> dir = {
        {0, 1},  // right
        {0, -1}, // left
        {1, 0},  // down
        {-1, 0}  // up
};
void solve() {
    ll n,ans=LONG_LONG_MIN;
    cin>>n;
    vector<ll>vc(n);
    for (int i=0 ;  i<n ; ++i){
        cin>>vc[i];
    }
    ll sz=n;
    for (int i=0 ; i<n ; ++i){
        ll sum=0;
        for (int j=0 ; j<sz ; ++j)
            sum+=vc[j];
        if(!i)
            ans=max(ans,sum);
        else
            ans=max(ans,max(sum ,(-sum)));
        for (int k=0 ; k<sz-1;++k){
            vc[k]=vc[k+1]-vc[k];
        }
        sz--;
    }
    cout<<ans<<"\n";
}
int main (){
    khatun
    Time
    //cout<<fixed<< setprecision(9)<<( double )5/3 ;
    int tc=1;
    cin>>tc;
    for (int i=1 ; i<= tc ; ++i){
        solve();
    }
    return 0;
}

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <bits/stdc++.h>
#include <bitset>
#include <cstdio>
#include <cctype>
#define ll long long
#define all(vc) vc.begin() , vc.end()
#define inf  0x3f3f3f3f3f3f3f3f
#define N 1000005
#define khatun ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Time   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
using namespace std;
const ll mod = 1e9+7, infinity = 1e4;

vector<pair<int, int>> dir = {
        {0, 1},  // right
        {0, -1}, // left
        {1, 0},  // down
        {-1, 0}  // up
};
void solve() {
    int n,ans=INT_MIN;
    cin>>n;
    vector<int>vc(n);
    for (int i=0 ;  i<n ; ++i){
        cin>>vc[i];
    }
    int sz=n;
    for (int i=0 ; i<n ; ++i){
        int sum=0;
        for (int j=0 ; j<sz ; ++j)
            sum+=vc[j];
        if(!i)
            ans=max(ans,sum);
        else
            ans=max(ans,max(sum ,(-sum)));
        for (int k=0 ; k<sz-1;++k){
            vc[k]=vc[k+1]-vc[k];
        }
        sz--;
    }
    cout<<ans<<"\n";
}
int main (){
    khatun
    Time
    //cout<<fixed<< setprecision(9)<<( double )5/3 ;
    int tc=1;
    cin>>tc;
    for (int i=1 ; i<= tc ; ++i){
        solve();
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
int res=-2e9;
int a[60],bk[60];
int n;
void solve() {
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        ans+=a[i];
    }
    for(int j=n;j>=2;j--) {
        long long sum=0;
        for(int i=1;i<j;i++) {
            a[i]=a[i+1]-a[i];
            sum+=a[i];
        }
        ans=max(ans,sum);
        ans=max(ans,-sum);

    }
    cout<<ans<<endl;
}

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

#include <bits/stdc++.h>
using namespace std;
int res=-2e9;
long long a[60];
int n;
void solve() {
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        ans+=a[i];
    }
    for(int j=n;j>=2;j--) {
        long long sum=0;
        for(int i=1;i<j;i++) {
            a[i]=a[i+1]-a[i];
            sum+=a[i];
        }
        ans=max(ans,sum);
        ans=max(ans,-sum);

    }
    cout<<ans<<endl;
}

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

Answer: 2


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef unordered_set<int> usi;
typedef set<int> si;
#define Pb push_back
#define Mp make_pair
#define FOR(i,a,b) for(int i = a ; i<b ; i++)
#define int long long

void solve(){
    int n;cin>>n;
    vector<int> arr(n);
    int sum = 0;
    FOR(i,0,n){
        cin>>arr[i];
        sum+=arr[i];
    }
    FOR(i,1,n)
    {
        int nsum = 0;
        int prevbefore = arr[i-1];
        int prev = arr[i-1];
        FOR(j,i,n)
        {
            prevbefore = arr[j];
            arr[j] = arr[j] - prev;
            prev = prevbefore;
            nsum+=arr[j];
        }
        if(abs(nsum)>sum){
            sum = abs(nsum);
            // cout<<i<<". "<<nsum<<endl;
        }
        // cout<<i<<". "<<nsum<<endl;
    }
    cout<<sum<<endl;
}

signed main(){
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef unordered_set<int> usi;
typedef set<int> si;
#define Pb push_back
#define Mp make_pair
#define FOR(i,a,b) for(int i = a ; i<b ; i++)

void solve(){
    int n;cin>>n;
    vector<int> arr(n);
    int sum = 0;
    FOR(i,0,n){
        cin>>arr[i];
        sum+=arr[i];
    }
    FOR(i,0,n)
    {
        int nsum = 0;
        FOR(j,0,n-1)
        {
            arr[j] = arr[j+1] - arr[j];
            nsum+=arr[j];
        }
        if(abs(nsum)>sum){
            sum = abs(nsum);
        }
    }
    cout<<sum<<endl;
}

int main(){
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;

    while (t--){
		int n;
		cin >> n;
        vector<ll>a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;

    while (t--){
		int n;
		cin >> n;
        vector<int>a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl;
    }
    return 0;
}

Answer: 1


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using ll = long long;

using namespace std;

vector<ll> replace( vector <ll> a){
    ll size = a.size();
    vector<ll> rep_a;

    for( ll i = 1;i < size; i++){
        rep_a.push_back(a[i] - a[i-1]);
    }

    return rep_a;

}

ll sum_array( vector<ll> a){
    ll sum = 0;
    for( ll i =0; i < a.size(); i++){

        sum += a[i];
    }

    return sum;

}

ll max_sum_sequence(ll n , vector <ll>& a){
    vector<ll> temp;

    if (n == 1) {
        return a[0];
    } else {
        ll sum = 0;
        sum = sum_array(a);

        for( ll j =0; j < n-1; j++ ){
        ll rep_sum = 0;
        temp = replace(a);
        a = temp;
        rep_sum = abs(sum_array(a));
        if( rep_sum > sum ) sum = rep_sum;
        }

            return sum;
    }
}

int main(){
    ll t;
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;
        vector<ll> a(n);
        for (ll i = 0; i < n; ++i) {
            cin >> a[i];
        }
        ll result = max_sum_sequence(n, a);
        cout << result << endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int max_sum_sequence(int n , vector <int>& a){
    if (n == 1) {
        return a[0];
    } else if (n == 2) {
        return max(a[0] + a[1], abs(a[0] - a[1]));
    } else {
        int sum = 0;
        for (int num : a) {
            sum += num;
        }
        return sum;
    }
}

int main(){
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        int result = max_sum_sequence(n, a);
        cout << result << endl;
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    int n; cin>>n;
    vector<ll> vi;
    ll ans=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        vi.push_back(x);
        ans+=x;
    }
    if(n==1){
        cout<<vi[0];
        return;
    }
    else if(n>2){
        for(int i=1;i<=n-2;i++){
            ll check=0;
            for(auto j:vi){
                check+=j;
            }
            ans=max(ans,check);
            ll sum=0;
            for(auto it=vi.begin();it!=vi.end()-1;it++){
                *it=*(it+1)-*(it);
                sum+=(*it);
            }
            ans=max(ans,max(sum,-sum));
            vi.pop_back();
        }
    }
    ll a=vi[0]+vi[1]; ll b=vi[0]-vi[1];
    ans=max(ans,(max(a,max(b,-b))));
    cout<<ans;
}

int main() {
    int t; cin >> t;
    while (t-- > 0) {
        solve();
        cout << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    int n; cin>>n;
    vector<ll> vi;
    ll ans=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        vi.push_back(x);
        ans+=x;
    }
    if(n==1){
        cout<<vi[0];
        return;
    }
    else if(n>2){
        for(int i=1;i<=n-2;i++){
            for(auto it=vi.begin();it!=vi.end()-1;it++){
                ll sum=0;
                *it=*(it)-*(it+1);
                sum+=(*it);
                sum=abs(sum);
                ans=max(ans,sum);
            }
            vi.pop_back();
        }
    }
    auto it=vi.begin();
    ll a=*(it+1)+*it; ll b=(*it)-*(it+1); ll c=*(it+1)-(*it);
    ans=max(ans,max(a,max(b,c)));
    cout<<ans;
}

int main() {
    int t; cin >> t;
    while (t-- > 0) {
        solve();
        cout << "\n";
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    int n;cin>>n;
    vector<ll> v;
    ll mx=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        mx+=x;
        v.push_back(x);
    }
    if(n==1){
        cout<<mx<<"\n";
        return;
    }
    mx=abs(mx);
    while(n>1){
        vector<ll> u;
        ll sum=0;
        for(int i=1;i<v.size();i++){
            ll dif=v[i]-v[i-1];
            sum+=dif;
            u.push_back(dif);
        }
        mx=max(mx,abs(sum));
        v=u;
        n--;
    }
    cout<<mx<<"\n";
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    int n;cin>>n;
    vector<ll> v;
    ll mx=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        mx+=x;
        v.push_back(x);
    }
    while(n>1){
        vector<ll> u;
        ll sum=0;
        for(int i=1;i<v.size();i++){
            ll dif=v[i]-v[i-1];
            sum+=dif;
            u.push_back(dif);
        }
        mx=max(mx,abs(sum));
        v=u;
        n--;
    }
    cout<<mx<<"\n";
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int n;
        cin>>n;
        vector<int>arr(n,0);
        for(int i=0;i<n;i++)
        cin>>arr[i];
        vector<int>temp=arr;
        int maxi=LLONG_MIN;
        while(true)
        {
            int sum=0ll;
            for(int i=0;i<temp.size();i++)
            {
                sum+=temp[i];
            }
            maxi=max(maxi,sum);
            reverse(temp.begin(),temp.end());
            if(temp.size()==1)
            break;
            vector<int>v;
            for(int i=1;i<temp.size();i++)
            {
                v.push_back(temp[i]-temp[i-1]);
            }
            sum=0;
            for(int i=0;i<v.size();i++)
            sum+=v[i];
            maxi=max(maxi,sum);
            int neg=(-1ll)*sum;
            maxi=max(maxi,neg);
            temp=v;
            if(temp.size()==1)
            {maxi=max(maxi,temp[0]);break;}
        }
        cout<<maxi<<endl;
    }
}

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int n;
        cin>>n;
        vector<int>arr(n,0);
        for(int i=0;i<n;i++)
        cin>>arr[i];
        vector<int>temp=arr;
        int maxi=LLONG_MIN;
        while(true)
        {
            int sum=0;
            for(int i=0;i<temp.size();i++)
            {
                sum+=temp[i];
            }
            maxi=max(maxi,sum);
            reverse(temp.begin(),temp.end());
            if(temp.size()==1)
            break;
            vector<int>v;
            for(int i=1;i<temp.size();i++)
            {
                v.push_back(temp[i]-temp[i-1]);
            }
            temp=v;
            if(temp.size()==1)
            {maxi=max(maxi,temp[0]);break;}
        }
        cout<<maxi<<endl;
    }
}

Answer: 1


#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <climits>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<long long> v;
        for(int i=0;i<n;i++){
            long long a;
            cin >> a;
            v.push_back(a);
        }
        long long ans = accumulate(v.begin(),v.end(),0LL);
        while(n > 1){
            vector<long long> v1;
            for(int i = 1;i<n;i++){
                v1.push_back(v[i] - v[i-1]);
            }
            ans = max(ans,abs(accumulate(v1.begin(),v1.end(),0LL)));
            for(int i = 0;i<n-1;i++){
                v[i] = v1[i];
            }
            n--;
        }
        cout << ans << endl;
    }
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <climits>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<long long> v;
        for(int i=0;i<n;i++){
            long long a;
            cin >> a;
            v.push_back(a);
        }
        long long ans = accumulate(v.begin(),v.end(),0LL);
        vector<long long> v1;
        while(n > 1){
            for(int i = 1;i<n;i++){
                v1.push_back(v[i] - v[i-1]);
            }
            ans = max(ans,abs(accumulate(v1.begin(),v1.end(),0LL)));
            for(int i = 0;i<n-1;i++){
                v[i] = v1[i];
            }
            v.clear();
            n--;
        }
        cout << ans << endl;
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll cur_sum(vector<ll> v) {
    ll sum = 0;
    for (int i = 0; i < v.size(); ++i) {
        sum += v[i];
    }
    return abs(sum);
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    if (n == 1) {
        cout << a[0] << '\n';
        return;
    }

    ll ans = accumulate(a.begin(), a.end(), 0LL);
    vector<ll> k = a;
    while (true) {
        vector<ll> temp;
        for (int i = 1; i < k.size(); ++i) {
            temp.push_back(k[i] - k[i - 1]);
        }
        k = temp;
        ans = max(ans, cur_sum(k));
        if (k.size() == 1) {
            break;
        }
        temp.clear();
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll cur_sum(vector<ll> v) {
    ll sum = 0;
    for (int i = 0; i < v.size(); ++i) {
        sum += v[i];
    }
    return abs(sum);
}

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

    if (n == 1) {
        cout << a[0] << '\n';
        return;
    }

    ll ans = cur_sum(a);
    vector<ll> k = a;
    while (true) {
        vector<ll> temp;
        for (int i = 1; i < k.size(); ++i) {
            temp.push_back(k[i] - k[i - 1]);
        }
        k = temp;
        ans = max(ans, cur_sum(k));
        if (k.size() == 1) {
            break;
        }
        temp.clear();
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;

#define putchar_unlocked putchar
#define getchar_unlocked getchar

struct Reader { int ch; operator bool() { return ch != EOF; } template<typename T> Reader &operator>>(T &x) { x = 0; int f = 1; ch = getchar_unlocked(); while (ch != EOF && (ch < '0' || ch > '9')) { if (ch == '-') f = -1; ch = getchar_unlocked(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar_unlocked(); } x *= f; return *this; } Reader &operator>>(char &s) { ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); s = ch; return *this; } Reader &operator>>(char *s) { char ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); while (ch != ' ' && ch != '\n' && ch != '\r' && ch != EOF) *(s++) = ch, ch = getchar_unlocked(); *s = '\0'; return *this; } } reader; struct Writer { template<typename T> Writer &operator<<(T x) { if (x < 0) { putchar_unlocked('-'); x = -x; } if (x > 9) *this << x / 10; putchar_unlocked(x % 10 + '0'); return *this; } Writer &operator<<(char ch) { putchar_unlocked(ch); return *this; } Writer &operator<<(const char *s) { for (int i = 0; s[i]; i++) putchar_unlocked(s[i]); return *this; } } writer;

#define cin reader
#define cout writer
#define endl '\n'

#define f(i, a, b) for (int i = (a), _##i = (b); i <= _##i; i++)
#define fr(i, a, b) for (int i = (a), _##i = (b); i >= _##i; i--)
typedef long long LL;

const int N = 55;
int n, a[N];
int solve() {
    cin >> n; f(i, 1, n) cin >> a[i];
    LL ans = accumulate(a + 1, a + n + 1, 0ll);
    while (n > 1) {
        f(i, 1, n - 1) a[i] = a[i + 1] - a[i];
        n--;
        LL sum = accumulate(a + 1, a + n + 1, 0ll);
        ans = max(ans, abs(sum));
    }
    return ans;
}
int main() {
    int T; cin >> T;
    while (T--) cout << solve() << endl;
}

#include <bits/stdc++.h>
using namespace std;

#define putchar_unlocked putchar
#define getchar_unlocked getchar

struct Reader { int ch; operator bool() { return ch != EOF; } template<typename T> Reader &operator>>(T &x) { x = 0; int f = 1; ch = getchar_unlocked(); while (ch != EOF && (ch < '0' || ch > '9')) { if (ch == '-') f = -1; ch = getchar_unlocked(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar_unlocked(); } x *= f; return *this; } Reader &operator>>(char &s) { ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); s = ch; return *this; } Reader &operator>>(char *s) { char ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); while (ch != ' ' && ch != '\n' && ch != '\r' && ch != EOF) *(s++) = ch, ch = getchar_unlocked(); *s = '\0'; return *this; } } reader; struct Writer { template<typename T> Writer &operator<<(T x) { if (x < 0) { putchar_unlocked('-'); x = -x; } if (x > 9) *this << x / 10; putchar_unlocked(x % 10 + '0'); return *this; } Writer &operator<<(char ch) { putchar_unlocked(ch); return *this; } Writer &operator<<(const char *s) { for (int i = 0; s[i]; i++) putchar_unlocked(s[i]); return *this; } } writer;

#define cin reader
#define cout writer
#define endl '\n'

#define f(i, a, b) for (int i = (a), _##i = (b); i <= _##i; i++)
#define fr(i, a, b) for (int i = (a), _##i = (b); i >= _##i; i--)
typedef long long LL;

const int N = 55;
int n;
LL a[N];
LL solve() {
    cin >> n; f(i, 1, n) cin >> a[i];
    LL ans = accumulate(a + 1, a + n + 1, 0ll);
    while (--n >= 1) {
        f(i, 1, n) a[i] = a[i + 1] - a[i];
        LL sum = accumulate(a + 1, a + n + 1, 0ll);
        ans = max(ans, abs(sum));
    }
    return ans;
}
int main() {
    int T; cin >> T;
    while (T--) cout << solve() << endl;
}

Answer: 2


#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n;
ll ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%lld", &a[i]), ans += a[i];
		for (int i = 1; i < n; i++) {
			sum = 0;
			for (int j = 1; i + j <= n; j++)
				a[j] -= a[j + 1], sum += a[j];
			if (sum < 0)
				sum *= -1;
			ans = max(ans, sum);
		}
		printf("%lld\n", ans);
	}
}

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		sum = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), sum += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		ans = abs(sum);
		for (; n > 1; --n) {
			sum = 0;
			for (int i = 1; i < n; i++)
				sum += (a[i] = a[i + 1] - a[i]);
			ans = max(ans, abs(sum));
		}
		printf("%d\n", ans);
	}
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define iii pair<int, ii>
#define fi first
#define se second
#define inf 1e16
const int N = 55;
int tc, n, a[N];
vector<int> chuyen(vector<int> &vec) {
    vector<int> tmp;
    reverse(vec.begin(),vec.end());
    for(int i = 1; i < vec.size(); i++) tmp.push_back(vec[i] - vec[i-1]);
    return tmp;
}
void solve() {
    vector<int> vec;
    int mx = 0;
    for(int i = 1; i <= n; i++) {
        vec.push_back(a[i]);
        mx += a[i];
    }
    while(vec.size()) {
        if(vec.size() == 1) {
            mx = max(mx, vec[0]);
            break;
        }
        int sum = 0;
        for(int i = 0; i < vec.size() - 1; i++) sum += vec[i] - vec[i+1];
        mx = max(mx, sum);
        vec = chuyen(vec);
    }
    cout << mx << '\n';
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen("main.inp","r")) {
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    }
    cin >> tc;
    while(tc--) {
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define iii pair<int, ii>
#define fi first
#define se second
#define inf 1e16
const int N = 55;
int tc, n, a[N];
vector<int> chuyen(vector<int> &vec) {
    vector<int> tmp;
    reverse(vec.begin(),vec.end());
    for(int i = 1; i < vec.size(); i++) tmp.push_back(vec[i] - vec[i-1]);
    return tmp;
}
void solve() {
    vector<int> vec;
    int mx = 0;
    for(int i = 1; i <= n; i++) {
        vec.push_back(a[i]);
        mx += a[i];
    }
    while(vec.size()) {
        if(vec.size() == 1) {
            mx = max(mx, vec[0]);
            break;
        }
        int sum = 0;
        for(int i = 0; i < vec.size() - 1; i++) sum += vec[i] - vec[i+1];
        mx = max(mx, max(sum,-sum));
        vec = chuyen(vec);
    }
    cout << mx << '\n';
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen("main.inp","r")) {
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    }
    cin >> tc;
    while(tc--) {
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        solve();
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

#define isEven(a) ((a & 1) == 0)
#define isOdd(a) ((a & 1) == 1)
#define isPowerof2(a) (((a) & ((a) - 1)) == 0)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define fi(a, b) for (int i = (a); (i) < (b); (i)++)
#define fj(a, b) for (int j = (a); (j) < (b); (j)++)
#define fx(m) for (auto &x : m)
#define fy(m) for (auto &y : m)
#define fz(m) for (auto &z : m)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define po pop_back
#define M (int)(1e9+7)
#define N (int)(2e5+20)
#define sc second
#define fs first
#define make_unique(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin());
#define print_vec(v) fx(v) cout << x << " "; cout << "\n"

void solve(){
	int n;
	cin>>n;
	vi a;
	fi(0,n){
		int x;
		cin>>x;
		a.pb(x);
	}
	ll sum=0;
	ll ans=INT_MIN;
	fi(0,n){
		sum+=a[i];
	}
	ans=max(sum,ans);
    int num=n-1;
    while(num--){
    	int j=1;
    	ll sum=0;
    	int n=a.size();
    	vector<int> temp;
    	while(j<n){
    		temp.pb(a[j]-a[j-1]);
    		sum+=a[j]-a[j-1];
    		j++;
    	}
    	a=temp;
    	ans=max(ans,abs(sum));
    }
    cout << ans << endl;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define isEven(a) ((a & 1) == 0)
#define isOdd(a) ((a & 1) == 1)
#define isPowerof2(a) (((a) & ((a) - 1)) == 0)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define fi(a, b) for (int i = (a); (i) < (b); (i)++)
#define fj(a, b) for (int j = (a); (j) < (b); (j)++)
#define fx(m) for (auto &x : m)
#define fy(m) for (auto &y : m)
#define fz(m) for (auto &z : m)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define po pop_back
#define M (int)(1e9+7)
#define N (int)(2e5+20)
#define sc second
#define fs first
#define make_unique(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin());
#define print_vec(v) fx(v) cout << x << " "; cout << "\n"

void solve(){
	ll n;
	cin>>n;
	vll a;
	fi(0,n){
		ll x;
		cin>>x;
		a.pb(x);
	}
	ll sum=0;
	ll ans=INT_MIN;
	fi(0,n){
		sum+=a[i];
	}
	ans=max(sum,ans);
    ll num=n-1;
    while(num--){
    	ll j=1;
    	ll sum=0;
    	ll n=a.size();
    	vector<ll> temp;
    	while(j<n){
    		temp.pb(a[j]-a[j-1]);
    		sum+=a[j]-a[j-1];
    		j++;
    	}
    	a=temp;
    	ans=max(ans,abs(sum));
    }
    cout << ans << endl;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    long long x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        long long sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    int n;
    cin>>n;
    vector<int> a(n+10);
    int x=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(int i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
    int n;
    cin >> n;

    vector<ll> nums(n);
    for (auto& a : nums)
        cin >> a;

    ll sum = LLONG_MIN;

    for (int i = 0; i < n; ++i)
    {
        ll runningsum = 0;

        for (int j = 0; j < n - i; ++j)
        {
            runningsum += nums[j];
        }
        if (i == 0)
            sum = max(sum, runningsum);
        else
            sum = max(sum, max(runningsum, -runningsum));

        for (int j = 0; j < n - i - 1; ++j)
        {
            nums[j] = nums[j + 1] - nums[j];
        }
    }

    cout << sum << '\n';
}
return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
    int n;
    cin >> n;

    vector<int> nums(n);
    for (auto& a : nums)
        cin >> a;

    ll sum = LLONG_MIN;

    for (int i = 0; i < n; ++i)
    {
        ll runningsum = 0;

        for (int j = 0; j < n - i; ++j)
        {
            runningsum += nums[j];
        }
        if (i == 0)
            sum = max(sum, runningsum);
        else
            sum = max(sum, max(runningsum, -runningsum));

        for (int j = 0; j < n - i - 1; ++j)
        {
            nums[j] = nums[j + 1] - nums[j];
        }
    }

    cout << sum << '\n';
}
return 0;
}

Answer: 1


/*Don Paul*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define el __int128

#define vl vector<ll>
#define ust unordered_set
#define ump unordered_map
#define prq priority_queue

#define pb push_back
#define pp pop_back
#define sz(x) ((int)x.size())
#define be(x) x.begin(), x.end()
#define farr(i, arr) for(int i=0; i<arr.size(); ++i)
#define fpr(it, m) for(auto it=m.begin(); it!=m.end(); ++it)

//Debugging tools

#define line cout<<"\n----------------------\n"
#define bline cout<<"\n======================\n"
#define parr(arr) for(int i=0; i<arr.size(); ++i) cout<<arr[i]<<" "; cout<<"\n";
#define pset(s) for(auto i=s.begin(); i!=s.end(); ++i) cout<<*i<<" "; cout<<"\n";
#define pmap(m) for(auto i=m.begin(); i!=m.end(); ++i) cout<<i->first<<" - "<<i->second<<"\n";

ll mod = 1e9 + 7;
ll inf = 7e18;

/*======================================================================================================================*/

ll find(vl &nums)
{
    ll i = 0;
    ll mx = -1e18;
    ll mn = 1e18;

    while(sz(nums) != 1)
    {
        ll sum = 0;

        for(ll i=0; i<sz(nums)-1; ++i)
        {
            nums[i] = nums[i+1] - nums[i];
            // cout<<nums[i]<<" ";

            sum += nums[i];
        }

        nums.pop_back();

        // cout<<"\n";
        // cout<<sum<<"\n";

        mx = max(mx, sum);
        mn = min(mn,sum);

        // line;
        ++i;
    }

    mn = -mn;
    return max(mn, mx);

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);cerr.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif

    int ti;
    cin>>ti;

    ll x;

    while(ti--)
    {
        ll n;
        cin>>n;

        vl nums;
        vl tnums;
        ll sum = 0;

        ll s1 = 0;
        ll s2 = 0;

        for(ll i=0; i<n; ++i)
        {
            cin>>x;

            if(x%2 == 0)
                s1 += x;
            else
                s2 += x;

            sum += x;
            nums.pb(x);
        }

        tnums = nums;

        // parr(nums);
        // cout<<sum<<"\n";

        ll ans = find(nums);

        if(s1 < s2)
            reverse(be(nums));

        ans = max(ans, sum);

        cout<<ans<<"\n";

        // line;

    }

    return 0;
}

/*Don Paul*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define el __int128

#define vl vector<ll>
#define ust unordered_set
#define ump unordered_map
#define prq priority_queue

#define pb push_back
#define pp pop_back
#define sz(x) ((int)x.size())
#define be(x) x.begin(), x.end()
#define farr(i, arr) for(int i=0; i<arr.size(); ++i)
#define fpr(it, m) for(auto it=m.begin(); it!=m.end(); ++it)

//Debugging tools

#define line cout<<"\n----------------------\n"
#define bline cout<<"\n======================\n"
#define parr(arr) for(int i=0; i<arr.size(); ++i) cout<<arr[i]<<" "; cout<<"\n";
#define pset(s) for(auto i=s.begin(); i!=s.end(); ++i) cout<<*i<<" "; cout<<"\n";
#define pmap(m) for(auto i=m.begin(); i!=m.end(); ++i) cout<<i->first<<" - "<<i->second<<"\n";

ll mod = 1e9 + 7;
ll inf = 7e18;

/*======================================================================================================================*/

ll find(vl &nums)
{
    ll i = 0;
    ll mx = -1e18;
    ll mn = 1e18;

    while(sz(nums) != 1)
    {
        ll sum = 0;

        for(ll i=0; i<sz(nums)-1; ++i)
        {
            nums[i] = nums[i+1] - nums[i];
            // cout<<nums[i]<<" ";

            sum += nums[i];
        }

        nums.pop_back();

        // cout<<"\n";
        // cout<<sum<<"\n";

        mx = max(mx, sum);
        mn = min(mx,sum);

        // line;
        ++i;
    }

    mn = -mn;
    return max(mn, mx);

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);cerr.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif

    int ti;
    cin>>ti;

    ll x;

    while(ti--)
    {
        ll n;
        cin>>n;

        vl nums;
        vl tnums;
        ll sum = 0;

        ll s1 = 0;
        ll s2 = 0;

        for(ll i=0; i<n; ++i)
        {
            cin>>x;

            if(x%2 == 0)
                s1 += x;
            else
                s2 += x;

            sum += x;
            nums.pb(x);
        }

        tnums = nums;

        // parr(nums);
        // cout<<sum<<"\n";

        ll ans = find(nums);

        if(s1 < s2)
            reverse(be(nums));

        ans = max(ans, sum);

        cout<<ans<<"\n";

        // line;

    }

    return 0;
}

Answer: 1


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<>())
#define fo(n) for (int i = 0; i < n; i++)
#define fo1(n) for (int i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define ll long long
#define Inf (ll)1e17 + 7
#define pi 3.1415926536
#define gcd __gcd
#define vi vector<int>
#define vl vector<ll>
#define nl '\n'
#define min_priority priority_queue<ll, vector<ll>, greater<ll>>
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
#define show(a)           \
    for (auto e : a)      \
        cout << e << " "; \
    cout << nl;
#define rY               \
    cout << "YES" << nl; \
    return;
#define rN              \
    cout << "NO" << nl; \
    return;
#define rr return
const ll mod = 1e9 + 7;
void Solve()
{
    ll n, m, x, y, z, i, j, k, l, r, q, W;
    cin >> n;
    vl v(n);
    for (i = 0; i < n; i++)
        cin >> v[i];
    ll ans = -1 * Inf;
    x = 0;
    for (auto e : v)
    {
        x += e;
    }
    ans = max(ans, x);
    while (v.size() > 1)
    {

        vector<ll> v1 = v;
        for (i = 1; i < v.size(); i++)
        {
            v[i - 1] = v[i] - v[i - 1];
        }
        v.pop_back();
        reverse(all(v1));
        for (i = 1; i < v1.size(); i++)
        {
            v1[i - 1] = v1[i] - v1[i - 1];
        }
        v1.pop_back();
        y = 0;
        for (auto e : v1)
        {
            y += e;
        }
        ans = max(ans, y);
        x = 0;
        for (auto e : v)
        {
            x += e;
        }
        ans = max(ans, x);
        if (x < y)
            v = v1;
    }
    ans = max(ans, v[0]);
    cout << ans << nl;
}
int main()
{
    op();
    int test = 1, c = 1;
    cin >> test;
    while (test--)
    {
        // cin.ignore();
        // cout << "Case " << c++ << ": ";
        Solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<>())
#define fo(n) for (int i = 0; i < n; i++)
#define fo1(n) for (int i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define ll long long
#define Inf (ll)1e17 + 7
#define pi 3.1415926536
#define gcd __gcd
#define vi vector<int>
#define vl vector<ll>
#define nl '\n'
#define min_priority priority_queue<ll, vector<ll>, greater<ll>>
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
#define show(a)           \
    for (auto e : a)      \
        cout << e << " "; \
    cout << nl;
#define rY               \
    cout << "YES" << nl; \
    return;
#define rN              \
    cout << "NO" << nl; \
    return;
#define rr return
const ll mod = 1e9 + 7;
void Solve()
{
    ll n, m, x, y, z, i, j, k, l, r, q, W;
    cin >> n;
    vl v(n);
    for (i = 0; i < n; i++)
        cin >> v[i];
    ll ans = -1 * Inf;
    while (v.size() > 1)
    {
        x = 0;
        for (auto e : v)
        {
            x += e;
        }
        ans = max(ans, x);
        vector<ll> v1 = v;
        for (i = 1; i < v.size(); i++)
        {
            v[i - 1] = v[i] - v[i - 1];
        }
        v.pop_back();
        reverse(all(v1));
        for (i = 1; i < v1.size(); i++)
        {
            v1[i - 1] = v1[i] - v1[i - 1];
        }
        v1.pop_back();
        y = 0;
        for (auto e : v1)
        {
            y += e;
        }
        ans = max(ans, y);
        if (x < y)
            v = v1;
    }
    ans = max(ans, v[0]);
    cout << ans << nl;
}
int main()
{
    op();
    int test = 1, c = 1;
    cin >> test;
    while (test--)
    {
        // cin.ignore();
        // cout << "Case " << c++ << ": ";
        Solve();
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#define ll long long int
#define fr(i,j,n) for(i=j;i<n;i++)
#define srt(a) sort(a.begin(),a.end())
#define srtr(a) sort(a.begin(),a.end(),greater<ll>())
#define rvr(a) reverse(a.begin(),a.end())
#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin())
#define mxel(a) *max_element(a.begin(),a.end())
#define mnel(a) *min_element(a.begin(),a.end())
#define ve vector<ll>
#define vep vector<pair<ll,ll>>
#define vee vector<vector<ll>>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (auto &i : v)
        is >> i;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v)
{
    for (auto &i : v)
        os << i << ' ';
    return os;
}
const ll M=998244353;
const ll N=4e5+2;
ll a[1010];
void solve()
{
    ll n,i;cin >> n;fr(i,1,n+1)cin >> a[i];ll j,k=n,ans,an=-N;//if(n==1) {cout << a[1] << endl;return;}
    fr(i,1,n+1){
        ans=0;fr(j,1,k+1) ans+=a[j];
        if(i==1)an=max(an,ans);
        else an=max(an,max(ans,(-ans)));
        fr(j,1,k)a[j]=(a[j+1]-a[j]);
        //if(n==1) if(ans<0) an=max(an,-ans);
        k--;
    }
    cout << an << endl;
}
int main()
{
    ll testcase=1;
    cin >> testcase;
    while(testcase--) solve();
    return 0;
}

#include<bits/stdc++.h>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#define ll long long int
#define fr(i,j,n) for(i=j;i<n;i++)
#define srt(a) sort(a.begin(),a.end())
#define srtr(a) sort(a.begin(),a.end(),greater<ll>())
#define rvr(a) reverse(a.begin(),a.end())
#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin())
#define mxel(a) *max_element(a.begin(),a.end())
#define mnel(a) *min_element(a.begin(),a.end())
#define ve vector<ll>
#define vep vector<pair<ll,ll>>
#define vee vector<vector<ll>>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (auto &i : v)
        is >> i;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v)
{
    for (auto &i : v)
        os << i << ' ';
    return os;
}
const ll M=998244353;
const ll N=4e5+2;
void solve()
{
    ll n;cin >> n;ve a(n);cin >> a;ll i,ans,an=-N;if(n==1) {cout << a[0] << endl;return;}
    while(n){
        ans=0;fr(i,0,n) ans+=a[i];
        if(n==1)an=max(an,ans);
        else an=max(an,max(ans,(-ans)));
        fr(i,0,n)a[i]=(a[i+1]-a[i]);
        //if(n==1) if(ans<0) an=max(an,-ans);
        n--;
    }
    cout << an << endl;
}
int main()
{
    ll testcase=1;
    cin >> testcase;
    while(testcase--) solve();
    return 0;
}

Answer: 1


#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }

        // Candidate 0: doing nothing.
        long long baseSum = 0;
        for(auto x : a) baseSum += x;
        long long ans = baseSum;

        // We'll simulate consecutive difference operations.
        // dp[0] is the original sequence.
        vector<vector<long long>> dp;
        dp.push_back(a);

        // Continue while the current sequence has at least 2 elements.
        for (int k = 0; dp[k].size() > 1; k++){
            vector<long long> nxt;
            for (int i = 0; i + 1 < dp[k].size(); i++){
                nxt.push_back(dp[k][i+1] - dp[k][i]);
            }
            dp.push_back(nxt);
            long long candidate;
            if(nxt.size() == 1)
                candidate = llabs(nxt[0]);
            else
                candidate = llabs(nxt.back() - nxt.front());
            ans = max(ans, candidate);
        }

        cout << ans <<endl;
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

// Recursive function that returns the maximum final sum obtainable
// from the current sequence using allowed operations.
long long solveSequence(const vector<long long>& seq) {
    long long s = 0;
    for (auto x : seq)
        s += x;
    long long best = s;  //do nothing and take the sum

    int n = seq.size();
    if(n >= 2) {
        // perform one difference operation.
        // By reversing if necessary, we can obtain |last - first|
        best = max(best, llabs(seq.back() - seq.front()));

        // Compute the difference sequence (in natural order).
        vector<long long> diffSeq(n - 1);
        for (int i = 0; i < n - 1; i++){
            diffSeq[i] = seq[i+1] - seq[i];
        }
        //continue operations on the difference sequence.
        best = max(best, solveSequence(diffSeq));
    }
    return best;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }

        // If the sequence has only one element, output it.
        if(n == 1){
            cout << a[0] <<endl;
            continue;
        }

        long long ans = solveSequence(a);
        cout << ans <<endl;
    }
    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

// Main problem-solving function
void solve() {
    int n;
    cin >> n;
    vll v(n), k;
    for(auto &a: v) cin >> a;
    ll ans = accumulate(all(v),0LL);
    while(n > 0){
        for(int i = 0; i < n-1; ++i){
            k.pb(v[i+1] - v[i]);
        }
        if (!k.empty()) {
            ans = max(ans, abs(accumulate(all(k), 0LL)));
        }
        for(int i = 0; i < n-1; ++i){
            v[i] = k[i];
        }
        k.clear();
        n--;
    }
    cout << ans << endl;

}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

// Main problem-solving function
void solve() {
    int n;
    cin >> n;
    vii v(n), k;
    for(auto &a: v) cin >> a;
    ll ans = accumulate(all(v),0LL);
    while(n > 0){
        for(int i = 0; i < n-1; ++i){
            k.pb(v[i+1] - v[i]);
        }
        if (!k.empty()) {
            ans = max(ans, abs(accumulate(all(k), 0LL)));
        }
        for(int i = 0; i < n-1; ++i){
            v[i] = k[i];
        }
        k.clear();
        n--;
    }
    cout << ans << endl;

}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Answer: 1


// source problem :
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define lb lower_bound
#define ub upper_bound
#define MASK(i) (1LL << (i))
const int inf = 1e18;
void ckmax(int& f, int s)
{
    f = (f > s ? f : s);
}
void ckmin(int& f, int s)
{
    f = (f < s ? f : s);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int &i : a) cin >> i;
        n--;
        int ans = accumulate(all(a), 0);
        while (n--)
        {
            reverse(all(a));
            for (int i = 1; i < a.size(); i++)
            {
                a[i - 1] = a[i] - a[i - 1];
            }
            a.pop_back();
            ckmax(ans, accumulate(all(a), 0));
        }
        cout << ans << '\n';
    }
    return 0;
}

// source problem :
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define lb lower_bound
#define ub upper_bound
#define MASK(i) (1LL << (i))
const int inf = 1e18;
void ckmax(int& f, int s)
{
    f = (f > s ? f : s);
}
void ckmin(int& f, int s)
{
    f = (f < s ? f : s);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int &i : a) cin >> i;
        n--;
        int ans = accumulate(all(a), 0);
        while (n--)
        {
            for (int i = 1; i < a.size(); i++)
            {
                a[i - 1] = a[i] - a[i - 1];
            }
            a.pop_back();
            ckmax(ans, abs(accumulate(all(a), 0LL)));
        }
        cout << ans << '\n';
    }
    return 0;
}

Answer: 2


#include <stdio.h>

int main(){
  int t;
  scanf("%d",&t);
  while(t-- > 0){
    int n;
    scanf("%d",&n);
    long long arr[n];
    long long sum = 0;
    for(int i=0; i<n; ++i){
      scanf("%lld",&arr[i]);
      sum += arr[i];
    }
    long long max = sum;
    while(n >= 2){
      sum = 0;
      long long sum2 = arr[n-1] - arr[0];
      long long sum2rev = -sum2;
      for(int i=0; i<n-1; ++i){
        sum += arr[i];
        arr[i] = arr[i+1] - arr[i];
      }
      sum += arr[n-1];
      n--;
      if(max < sum){
        max = sum;
      }
      if(max < sum2){
        max = sum2;
      }
      if(max < sum2rev){
        max = sum2rev;
      }
    }
    printf("%lld\n",max);
  }
  return 0;
}

#include <stdio.h>

int main(){
  int t;
  scanf("%d",&t);
  while(t-- > 0){
    int n;
    scanf("%d",&n);
    int arr[n];
    int sum = 0;
    for(int i=0; i<n; ++i){
      scanf("%d",&arr[i]);
      sum += arr[i];
    }
    int max = sum;
    while(n >= 2){
      sum = 0;
      int sum2 = arr[n-1] - arr[0];
      int sum2rev = -sum2;
      for(int i=0; i<n-1; ++i){
        sum += arr[i];
        arr[i] = arr[i+1] - arr[i];
      }
      sum += arr[n-1];
      n--;
      if(max < sum){
        max = sum;
      }
      if(max < sum2){
        max = sum2;
      }
      if(max < sum2rev){
        max = sum2rev;
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

void solve(int T) {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &i: v) cin >> i;
    if (n == 1) {
        cout << v[0];
        return;
    }
    ll ans = accumulate(v.begin(), v.end(), 0ll);
    while (v.size() > 1) {
        for (int i = 0; i < (int) v.size() - 1; ++i) {
            v[i] = v[i + 1] - v[i];
        }
        v.pop_back();
    }
    ans = max(ans, abs(accumulate(v.begin(), v.end(), 0ll)));
    cout << ans;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve(i);
        cout << '\n';
    }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

void solve(int T) {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &i: v) cin >> i;
    if (n == 1) {
        cout << v[0];
        return;
    }
    ll ans = accumulate(v.begin(), v.end(), 0ll);
    while (v.size() > 1) {
        for (int i = 0; i < (int) v.size() - 1; ++i) {
            v[i] = v[i + 1] - v[i];
        }
        v.pop_back();
        ans = max(ans, abs(accumulate(v.begin(), v.end(), 0ll)));
//        cout << abs(accumulate(v.begin(), v.end(), 0ll)) << '\n';
    }
    cout << ans;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve(i);
        cout << '\n';
    }
}

Answer: 2


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;
        vector<long long> arr(n + 1);

        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
        }

        int row = n;
        long long sum = -1e18;

        for(int j = 1; j <= n; j++) {
            long long ans = 0;
            for(int b = 1; b <= row; b++) {
                ans += arr[b];
            }

            if(j == 1) {
                sum = max(ans, sum);
            } else {
                sum = max(sum, max(-ans, ans));
            }

            for(int a = 1; a < row; a++) {
                arr[a] = arr[a + 1] - arr[a];
            }
            row--;
        }

        cout << sum << endl;
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;
        vector<int> arr(n + 1);

        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
        }

        int row = n;
        long long sum = -1e18;

        for(int j = 1; j <= n; j++) {
            long long ans = 0;
            for(int b = 1; b <= row; b++) {
                ans += arr[b];
            }

            if(j == 1) {
                sum = max(ans, sum);
            } else {
                sum = max(sum, max(-ans, ans));
            }

            for(int a = 1; a < row; a++) {
                arr[a] = arr[a + 1] - arr[a];
            }
            row--;
        }

        cout << sum << endl;
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define  nn                     cout<<"NO"<<endl
#define  hh                     cout<<"YES"<<endl
#define all(x)                   x.begin(),x.end()
#define rall(x)                 x.rbegin(),x.rend()
#define ct(x)                   cout<<x<<endl
#define TT                      TALHA TASEEN
using namespace std;
using ll = long long;
bool isPrime(ll n)
{
    for(int i=2; i*i<=n; i++)   if(n%i==0) return false;
    return true;
}
ll gcd(ll a,ll b)
{
    return (__gcd(a,b));
}
ll lcm(ll a,ll b)
{
    return (a/(gcd(a,b))*b);
}
void talha();
int  main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)talha();
    return 0;
}
void talha()
{
    int n;
    cin>>n;
    vector<int>v(n),vv;
    ll sm=0,ans=0;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sm+=v[i];
    }
    while(n>1)
    {
        ans=0;
        for(int j=0; j<n-1; j++)vv.push_back(v[j+1]-v[j]);
//        for(auto x:vv)
//        {
//            cout<<x<<" ";
//        }
//        cout<<endl;
        for(int j=0; j<vv.size(); j++)ans+=vv[j];
        sm=max(sm,abs(ans));
        for(int i=0; i<n-1; i++)v[i]=vv[i];
        vv.clear(),n--;
    }
    ct(sm);
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define  nn                     cout<<"NO"<<endl
#define  hh                     cout<<"YES"<<endl
#define all(x)                   x.begin(),x.end()
#define rall(x)                 x.rbegin(),x.rend()
#define ct(x)                   cout<<x<<endl
#define TT                      TALHA TASEEN
using namespace std;
using ll = long long;
bool isPrime(ll n)
{
    for(int i=2; i*i<=n; i++)   if(n%i==0) return false;
    return true;
}
ll gcd(ll a,ll b)
{
    return (__gcd(a,b));
}
ll lcm(ll a,ll b)
{
    return (a/(gcd(a,b))*b);
}
void talha();
int  main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)talha();
    return 0;
}
void talha()
{
    ll n;
    cin>>n;
    vector<ll>v(n),vv;
    ll sm=0,ans=0;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sm+=v[i];
    }
    while(n>1)
    {
        ans=0;
        for(int j=0; j<n-1; j++)vv.push_back(v[j+1]-v[j]);
        for(int j=0; j<vv.size(); j++)ans+=vv[j];
        sm=max(sm,abs(ans));
        for(int i=0; i<n-1; i++)v[i]=vv[i];
        vv.clear(),n--;
    }
    ct(sm);
}

Answer: 2


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define pll pair<ll,ll>
#define pllv pair<ll,vector<ll>>
#define all(a) a.begin(),a.end()
#define ump unordered_map
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define DEATH_NOTE ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define rep(a,b) for(ll i=a;i<b;i++)
//const ll sz=1001;
const ll mod=1e9+7;
const ll INF=1e18+10;

void solve()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ans = -INF;
    for(ll i=0;i<n;i++) cin>>a[i];
    vector<ll> v = a;
    if(v.size()== 1) {
        cout<<v[0]<<endl;
        return;
    }
    while(v.size()>1) {
        ll stSum = 0;
        for(ll i=0;i<v.size();i++) stSum+=v[i];
        ans=max(ans,abs(stSum));
        ll reducedSum = 0;
        vector<ll> reducedV;
        for(ll i=1;i<v.size();i++) {
            reducedV.push_back(v[i]-v[i-1]);
            reducedSum+=(v[i]-v[i-1]);
        }
        ans=max(ans,abs(reducedSum));
        v=reducedV;
    }
    cout<<ans<<endl;
}
int main()
{
    DEATH_NOTE

    ll t;
    t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define pll pair<ll,ll>
#define pllv pair<ll,vector<ll>>
#define all(a) a.begin(),a.end()
#define ump unordered_map
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define DEATH_NOTE ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define rep(a,b) for(ll i=a;i<b;i++)
//const ll sz=1001;
const ll mod=1e9+7;
const ll INF=1e18+10;

void solve()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ans = -INF;
    for(ll i=0;i<n;i++) cin>>a[i];
    vector<ll> v = a;
    if(v.size()== 1) {
        cout<<v[0]<<endl;
        return;
    }
    while(v.size()>1) {
        ll stSum = 0;
        for(ll i=0;i<v.size();i++) stSum+=v[i];
        ans=max(ans,stSum);
        ll reducedSum = 0;
        vector<ll> reducedV;
        for(ll i=1;i<v.size();i++) {
            reducedV.push_back(v[i]-v[i-1]);
            reducedSum+=(v[i]-v[i-1]);
        }
        ans=max(ans,abs(reducedSum));
        v=reducedV;
    }
    cout<<ans<<endl;
}
int main()
{
    DEATH_NOTE

    ll t;
    t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " ";_print(x) ;cerr << endl;
#else
#define debug(x);
#endif

typedef long long ll;

template<class T> void _print(T x) { cerr << x << " "; }

// template<class T> void _print(vector<T> v1);
template<class T> void _print(vector<T> v1){for(T& ele : v1){_print(ele);}}

void stdInput(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif
}

ll solve(vector<int>& v1,int n)
{
	ll mxSum = LLONG_MIN;

	mxSum = accumulate(v1.begin(),v1.end(),0ll);
	debug(mxSum);
	vector<ll> tmp;

	while(n > 1){
		// debug(mxSum);
		for(int i = 0;i < n-1;++i){
			tmp.push_back(v1[i+1] - v1[i]);
		}
		ll sum = 0;
		for(ll &ele : tmp){
			sum += ele;
		}
		// mxSum = max(mxSum,abs(accumulate(tmp.begin(),tmp.end(),0ll)));
		// debug(v1);
		// cout << sum << endl;

		for(int i = 0;i < n-1;i++){
			v1[i] = tmp[i];
		}
		mxSum = max(mxSum,abs(sum));
		tmp.clear();
		n--;
	}
	return mxSum;

}
int main()
{
	stdInput();
	int T;
	cin >> T;
	while(T--)
	{
		int n;
		cin >> n;
		vector<int> v1(n);
		for(int &i : v1){
			cin >> i;
		}
		cout << solve(v1,n) << endl;
	}
}

#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " ";_print(x) ;cerr << endl;
#else
#define debug(x);
#endif

typedef long long ll;

template<class T> void _print(T x) { cerr << x << " "; }

// template<class T> void _print(vector<T> v1);
template<class T> void _print(vector<T> v1){for(T& ele : v1){_print(ele);}}

void stdInput(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif
}

ll solve(vector<ll>& v1,int n)
{
	ll mxSum = LLONG_MIN;

	mxSum = accumulate(v1.begin(),v1.end(),0ll);
	debug(mxSum);
	vector<ll> tmp;

	while(n > 1){
		// debug(mxSum);
		for(int i = 0;i < n-1;++i){
			tmp.push_back(v1[i+1] - v1[i]);
		}
		ll sum = 0;
		for(ll &ele : tmp){
			sum += ele;
		}
		// mxSum = max(mxSum,abs(accumulate(tmp.begin(),tmp.end(),0ll)));
		// debug(v1);
		// cout << sum << endl;

		for(int i = 0;i < n-1;i++){
			v1[i] = tmp[i];
		}
		mxSum = max(mxSum,abs(sum));
		tmp.clear();
		n--;
	}
	return mxSum;

}
int main()
{
	stdInput();
	int T;
	cin >> T;
	while(T--)
	{
		int n;
		cin >> n;
		vector<ll> v1(n);
		for(ll &i : v1){
			cin >> i;
		}
		cout << solve(v1,n) << endl;
	}
}

Answer: 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,vec[0])<<endl;
}
signed main(){
    fastio();
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
//

#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);
    vector<int> New(n);
    int ans=0;
    for(int j=1;j<=n-1;j++){
        int sum=0;
        for(int i=0;i<=n-j;i++){
            sum+=vec[i];
        }
        ans=max(ans,sum);
        for(int i=0;i<n-j;i++){
            New[i]=(vec[i]-vec[i+1]);
        }
        swap(New,vec);
    }
    cout<<max(ans,abs(vec[0]))<<endl;

}
signed main(){
    fastio();
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
//

Answer: 1