ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 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;
}

Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 1:
#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;
    }
}

Code 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=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
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 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;
    }
}

Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 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; 
}

Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++20 

Code 1:
#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);
	}
}


Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++20 

Code 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;
}


Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 1:
#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;
}

Code 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(){
	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
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 1:
#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;
}

Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 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;
}

Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 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;
}


Code 2:
#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
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 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;
}


Code 2:
#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