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

Code 1:
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
using namespace std;
#define ll long long
#define re(i,b) for(ll i=0;i<b;i++)
#define rre(i,b) for(ll i=b;i>=0;i--)
#define dd long double
#define all(x) x.begin(), x.end()
#define rall(a) (a).rbegin(), (a).rend()
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define lire(v) for (auto &u : v) cin >> u;
#define aff(v) for (auto u : v) cout << u << " "; cout << endl;
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define mpcl map<char, ll>
#define vdd vector<dd>
#define vbo vector<bool>
#define mpll map<ll, ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vss vector<string>
#define vcc vector<char>
#define scc set<char>
#define sss set<string>
// sort(a.begin(), a.end(), [](int x, int y) {
//       return x % 2 < y % 2;
//     });
//fixed<<setprecision(6)
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll t;
    cin >> t;
    re(w,t){
       ll n;cin>>n;
       vll a(n);
       ll s=LLONG_MIN;
       
       re(i,n){
           ll s2=0;
           re(j,n-i){
               s2+=a[j];
           }
           if(i==0)s=max(s,s2);
           else s=max(s,max(s2,-(s2)));
           re(j,n-i-1)a[j]=a[j+1]-a[j];
       }
       cout<<s<<endl;
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
using namespace std;
#define ll long long
#define re(i,b) for(ll i=0;i<b;i++)
#define rre(i,b) for(ll i=b;i>=0;i--)
#define dd long double
#define all(x) x.begin(), x.end()
#define rall(a) (a).rbegin(), (a).rend()
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define lire(v) for (auto &u : v) cin >> u;
#define aff(v) for (auto u : v) cout << u << " "; cout << endl;
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define mpcl map<char, ll>
#define vdd vector<dd>
#define vbo vector<bool>
#define mpll map<ll, ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vss vector<string>
#define vcc vector<char>
#define scc set<char>
#define sss set<string>
// sort(a.begin(), a.end(), [](int x, int y) {
//       return x % 2 < y % 2;
//     });
//fixed<<setprecision(6)
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll t;
    cin >> t;
    re(w,t){
       ll n;cin>>n;
       vll a(n);
       ll s=LLONG_MIN;
       re(i,n){
           cin>>a[i];
       }
       re(i,n){
           ll s2=0;
           re(j,n-i){
               s2+=a[j];
           }
           if(i==0)s=max(s,s2);
           else s=max(s,max(s2,-(s2)));
           re(j,n-i-1)a[j]=a[j+1]-a[j];
       }
       cout<<s<<endl;
    }
    return 0;
}


Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 1:
#include <bits/stdc++.h>  
#define F first   
#define S second   
#define ll long long  
#define pll pair <ll, ll>  
#define pii pair <int, int>  
#define pb push_back
#define rnd srand(static_cast<unsigned int>(time(0)))
using namespace std;  
const int mod = 1e9 + 7;  
const int MAXN = 1e6 + 5;  
const int inf = 2e9;
void solve(){
    int n;
    ll mx = 0, sum = 0;
    cin >> n;
    vector <ll> a(n);
    for (int i = 0; i < n; i ++){
        cin >> a[i];
        sum += a[i];
    }
    if (n > 1) mx = max(mx, abs(sum));
    else mx = max(mx, sum);
    while((int)a.size() != 1){
        for (int i = 0; i < (int)a.size() - 1; i ++){
            a[i] *= (-1LL); 
            a[i] += a[i + 1];
        }
        a.pop_back();
        sum = 0;
        for (ll i : a)
            sum += i;
        mx = max(mx, abs(sum));
    }
    cout << mx << endl;
}
int main(){  
    ios_base::sync_with_stdio(0);  
    cin.tie(0);  
    cout.tie(0);  
    int t;
    cin >> t;
    while (t --)    
        solve();
}

Code 2:
#include <bits/stdc++.h>  
#define F first   
#define S second   
#define ll long long  
#define pll pair <ll, ll>  
#define pii pair <int, int>  
#define pb push_back
#define rnd srand(static_cast<unsigned int>(time(0)))
using namespace std;  
const int mod = 1e9 + 7;  
const int MAXN = 1e6 + 5;  
const int inf = 2e9;
void solve(){
    int n;
    ll mx = -2e18, sum = 0;
    cin >> n;
    vector <ll> a(n);
    for (int i = 0; i < n; i ++){
        cin >> a[i];
        sum += a[i];
    }
    mx = max(mx, sum);
    while((int)a.size() != 1){
        for (int i = 0; i < (int)a.size() - 1; i ++){
            a[i] *= (-1LL); 
            a[i] += a[i + 1];
        }
        a.pop_back();
        sum = 0;
        for (ll i : a)
            sum += i;
        if (n > 1) mx = max(mx, abs(sum));
        else mx = max(mx, sum);
    }
    cout << mx << endl;
}
int main(){  
    ios_base::sync_with_stdio(0);  
    cin.tie(0);  
    cout.tie(0);  
    int t;
    cin >> t;
    while (t --)    
        solve();
}

Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++20 

Code 1:
#include <bits/stdc++.h>

#define endl '\n'
typedef long long ll;
using namespace std;

template <typename T>T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template <typename T> T lcm(T a, T b) {return (a * b) / gcd(a, b);}
template <typename K> void print_vec(const vector<K>& vec) {for(size_t i = 0; i < vec.size(); ++i) {cout << vec[i];if(i != vec.size() - 1) {cout << " ";}}cout << endl;}

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

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

    ans = abs(ans);

    while (n > 1) {
        ll x = 0;
        for (int i = 0; i < n - 1; i++) {
            a[i] = a[i + 1] - a[i];
            x += a[i];
        }

        ans = max(ans, abs(x));
        n--;
    }

    cout << ans << endl;
}

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

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

Code 2:
#include <bits/stdc++.h>

#define endl '\n'
typedef long long ll;
using namespace std;

template <typename T>T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template <typename T> T lcm(T a, T b) {return (a * b) / gcd(a, b);}
template <typename K> void print_vec(const vector<K>& vec) {for(size_t i = 0; i < vec.size(); ++i) {cout << vec[i];if(i != vec.size() - 1) {cout << " ";}}cout << endl;}

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

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

    while (n > 1) {
        ll x = 0;
        for (int i = 0; i < n - 1; i++) {
            a[i] = a[i + 1] - a[i];
            x += a[i];
        }

        ans = max(ans, abs(x));
        n--;
    }

    cout << ans << endl;
}

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

    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>
using namespace std;
#define ll long long

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


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

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


Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define NMAX 55
#define pb push_back

using namespace std;

int v[NMAX];

int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        long long maxx = LONG_LONG_MIN;
        cin >> n;
        long long s = 0;
        for (int i = 1; i <= n; i++) {
            cin >> v[i];
            s += v[i];
        }
        maxx = max(maxx, s);
        int p = n;
        while(p > 1) {
            long long s1 = 0, s2 = 0;
            for (int i = 1; i < p; i++) {
                v[i] = v[i + 1] - v[i];
                s1 += v[i];
                s2 += -(v[i]);
            }
            p--;
            maxx = max(maxx, max(s1, s2));
        }
        if (n > 1)
            cout << maxx << '\n';
        else cout << v[1] << '\n';
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define NMAX 55
#define pb push_back

using namespace std;

long long v[NMAX];

int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        long long maxx = LONG_LONG_MIN;
        cin >> n;
        long long s = 0;
        for (int i = 1; i <= n; i++) {
            cin >> v[i];
            s += v[i];
        }
        maxx = max(maxx, s);
        int p = n;
        while(p > 1) {
            long long s1 = 0, s2 = 0;
            for (int i = 1; i < p; i++) {
                v[i] = v[i + 1] - v[i];
                s1 += v[i];
                s2 += -(v[i]);
            }
            p--;
            maxx = max(maxx, max(s1, s2));
        }
        if (n > 1)
            cout << maxx << '\n';
        else cout << v[1] << '\n';
    }
    return 0;
}


Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int> 
#define vvi vector<vi>
#define umi unordered_map<int,int>
#define usi unordered_set<int> 
#define all(x) x.begin(),x.end()
#define fr(i, n) for (long long i = 0; i < (n); i++)
using namespace std;

const int mod = 1e9+7;

int sol(vector<int> v) {
    int n = v.size();
    if (n == 1) {
        return v[0];
    }

    vi ki, kir;
    for (int i = 1; i < n; i++) {
        ki.pb(v[i] - v[i - 1]);
    }

    reverse(all(v));

    for (int i = 1; i < n; i++) {
        kir.pb(v[i] - v[i - 1]);
    }

    if (ki.empty() || kir.empty()) return 0; // Avoid infinite recursion

    return max({sol(ki), sol(kir)});
}

void solve() {
    int n;
    cin >> n;
    vi v(n);
    fr(i, n) {
        cin >> v[i];
    }
    
    int sm = accumulate(all(v), 0LL);
    int mi = sol(v);
    
    cout << max(mi, sm) << endl;
}

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


Code 2:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<ll> 
#define vvi vector<vi>
#define umi unordered_map<ll,ll>
#define usi unordered_set<ll> 
#define all(x) x.begin(),x.end()
#define fr(i, n) for (long long i = 0; i < (n); i++)
using namespace std;

const ll mod = 1e9+7;

vector<ll>sol(vector<ll> v) {
  ll n=v.size();
  vi ki;
  for(ll i=1;i<n;i++){
    ki.pb(v[i]-v[i-1]);
  }
  ll sm=accumulate(all(ki),0LL);
  if(sm<0){
    reverse(all(v));
    ki.clear();
    for(ll i=1;i<n;i++){
       ki.pb(v[i]-v[i-1]);
    }
  }
  return ki;
}

void solve() {
    ll n;
    cin >> n;
    vi v(n);
    fr(i, n) {
        cin >> v[i];
    }ll mx=INT_MIN;ll si=accumulate(all(v),0LL);
 while(!v.empty()){
    ll sm=accumulate(all(v),0LL);
    v=sol(v);
    mx=max(mx,sm);
}
cout<<max(mx,si)<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
}


Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define debug 0

int main(){
    int cases;
    scanf("%d",&cases);
    while(cases--){
        int n;
        cin >> n;
        int sum=0;
        vector<int> arr;
        int num;
        for(int i=0;i<n;i++){
            cin >> num;
            arr.push_back(num);
            sum+=arr[i];
           
        }
        vector<int> vec;
        vec.push_back(sum);
        while(arr.size()>1){
            int n=arr.size();
            if(arr[0] < arr[n-1])
            {
                vec.push_back(arr[n-1]-arr[0]);
                for(int i=0;i<n-1;i++)
                {
                    arr[i]=arr[i+1]-arr[i];
                }
                arr.pop_back();
            }
            else{
                vec.push_back(arr[0]-arr[n-1]);
                for(int i=0;i<n-1;i++)
                {
                    arr[i]=arr[i]-arr[i+1];
                }
                arr.pop_back();
            }
        }
        stable_sort(vec.begin(),vec.end());
        int m=vec.size();
        cout << vec[m-1] << endl;

    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define debug 0

int main(){
    long long int cases;
    scanf("%lld",&cases);
    while(cases--){
        long long int n;
        cin >> n;
        long long int sum=0;
        vector<long long int> arr;
        long long int num;
        for(long long int i=0;i<n;i++){
            cin >> num;
            arr.push_back(num);
            sum+=arr[i];
           
        }
        vector<long long int> vec;
        vec.push_back(sum);
        while(arr.size()>1){
            long long int n=arr.size();
            if(arr[0] < arr[n-1])
            {
                vec.push_back(arr[n-1]-arr[0]);
                for(long long int i=0;i<n-1;i++)
                {
                    arr[i]=arr[i+1]-arr[i];
                }
                arr.pop_back();
            }
            else{
                vec.push_back(arr[0]-arr[n-1]);
                for(long long int i=0;i<n-1;i++)
                {
                    arr[i]=arr[i]-arr[i+1];
                }
                arr.pop_back();
            }
        }
        stable_sort(vec.begin(),vec.end());
        long long int m=vec.size();
        cout << vec[m-1] << endl;

    }
}

Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t!=0){
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++) cin>>arr[i];
        
        long long maxi=LLONG_MIN;
        int now=n;
        for(int i=0;i<n;i++){
            long long sum=0;
            for(int j=0;j<now;j++){
                sum+=arr[j];
            }
            if(i==0){
                maxi=max(maxi,sum);
            }
            else{
                maxi=max(maxi,max(sum,(-sum)));
            }
            
            for(int j=0;j<now-1;j++){
                arr[j]=arr[j+1]-arr[j];
            }
            now--;
        }
        cout<<maxi<<endl;
        t--;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t!=0){
        int n;
        cin>>n;
        long long arr[n];
        for(int i=0;i<n;i++) cin>>arr[i];
        
        long long maxi=LLONG_MIN;
        int now=n;
        for(int i=0;i<n;i++){
            long long sum=0;
            for(int j=0;j<now;j++){
                sum+=arr[j];
            }
            if(i==0){
                maxi=max(maxi,sum);
            }
            else{
                maxi=max(maxi,max(sum,(-sum)));
            }
            
            for(int j=0;j<now-1;j++){
                arr[j]=arr[j+1]-arr[j];
            }
            now--;
        }
        cout<<maxi<<endl;
        t--;
    }
}

Answer: 2
Problem: 2062C - Cirno and Operations
Language: other

Code 1:
#include <stdio.h>
#include <math.h>
int main(){
    int n;
    scanf("%d\n",&n);
    long long int res[n];
    for (int i=0;i<n;i++){
        int k;
        long long int max=0;
        scanf("%d\n",&k);
        int arr[k];
        for (int j=0;j<k;j++){
            scanf("%d",&arr[j]);
            max=max+arr[j];
        }
        for (int y=1;y<k;y++){
            long long int temp=0,value=1;
            if (y%2==1){
                for (int u=0;u<y;u++){
                    temp=temp+(value)*((int)pow(-1,u))*(arr[k-1-u]-arr[u]);
                    value=(value*(y-1-u))/(u+1);
                }
            }
            else {
                for (int u=0;u<y;u++){
                    temp=temp+(value)*((int)pow(-1,u))*(arr[k-1-u]+arr[u]);
                    value=(value*(y-1-u))/(u+1);
                }
            }
            // printf("%d %d\n",y,temp);
            if (temp>max){
                max=temp;
            }
            else if (-1*temp>max){
                max=-1*temp;
            }
        }
        res[i]=max;
    }
    for (int b=0;b<n;b++){
        printf("%lld\n",res[b]);
    }
}

Code 2:
#include <stdio.h>
#include <math.h>
int main(){
    int n;
    scanf("%d\n",&n);
    long long int res[n];
    for (int i=0;i<n;i++){
        int k;
        long long int max=0;
        scanf("%d\n",&k);
        int arr[k];
        for (int j=0;j<k;j++){
            scanf("%d",&arr[j]);
            max=max+arr[j];
        }
        for (int y=1;y<k;y++){
            long long int temp=0,value=1;
            if (y%2==1){
                for (int u=0;u<y;u++){
                    temp=temp+(value)*((int)pow(-1,u))*(arr[k-1-u]-arr[u]);
                    value=(value*(y-1-u))/(u+1);
                }
            }
            else {
                for (int u=0;u<y;u++){
                    temp=temp+(value)*((int)pow(-1,u))*(arr[k-1-u]+arr[u]);
                    value=(value*(y-1-u))/(u+1);
                }
            }
            // printf("%d %d\n",y,temp);
            if (temp>max){
                max=temp;
            }
            if (-1*temp>max){
                max=-1*temp;
            }
        }
        res[i]=max;
    }
    for (int b=0;b<n;b++){
        printf("%lld\n",res[b]);
    }
}

Answer: 2
Problem: 2062C - Cirno and Operations
Language: c++17 

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

const int sz = 2e5 + 5;

void solve(){
    int n, sum = 0, ans = -1e9; cin >> n;
    vector<int>a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i]; sum += a[i];
    }
    ans = max(ans, sum); sum = 0;
    while(a.size() > 1){
        reverse(a.begin(), a.end());
        vector<int>b(a.size() - 1);
        for(int i = 1; i < a.size(); i++){
            b[i - 1] = a[i] - a[i - 1];
            sum += b[i - 1];
        }
        ans  = max(ans, abs(sum)); sum = 0;
        swap(a, b);
    }
    cout << ans << '\n';
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); 
    int t; cin >> t;
    while(t--) solve();
}

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

const int sz = 2e5 + 5;

void solve(){
    int n, sum = 0, ans = -1e9; cin >> n;
    vector<int>a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i]; sum += a[i];
    }
    ans = max(ans, sum); sum = 0;
    while(a.size() > 1){
        reverse(a.begin(), a.end());
        vector<int>b(a.size() - 1);
        for(int i = 1; i < a.size(); i++){
            b[i - 1] = a[i] - a[i - 1];
            sum += b[i - 1];
        }
        ans  = max(ans, sum); sum = 0;
        swap(a, b);
    }
    cout << ans << '\n';
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); 
    int t; cin >> t;
    while(t--) solve();
}

Answer: 1
Problem: 2062C - Cirno and Operations
Language: c++20 

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

int main() 
{
    int t;
    cin>>t;
    while(t--)
    {
      long long n;
      cin>>n;
      vector<long long> a(n);
      long long sum=0;
      for(auto&i:a)
      {
        cin>>i;
        sum+=i;
      }
      vector<long long> store;
      while(n>1)
      {
        for(int i=0;i<n-1;i++)
        {
          store.push_back(a[i+1]-a[i]);
        }
        
        long long sum2=0;
        for(auto&i:store)sum2+=i;
        
        sum=max(sum,abs(sum2));
        
        for(int i=0;i<store.size();i++)
        {
          a[i]=store[i];
        }
        a.pop_back();
        n--;
        store.clear();
      }
      cout<<sum<<endl;
    }
}


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

int main() 
{
    int t;
    cin>>t;
    while(t--)
    {
      long long n;
      cin>>n;
      vector<long long> a(n);
      long long sum=0;
      for(auto&i:a)
      {
        cin>>i;
        sum+=i;
      }
      vector<int> store;
      while(n>1)
      {
        for(int i=0;i<n-1;i++)
        {
          store.push_back(a[i+1]-a[i]);
        }
        
        long long sum2=0;
        for(auto&i:store)sum2+=i;
        
        sum=max(sum,abs(sum2));
        
        for(int i=0;i<store.size();i++)
        {
          a[i]=store[i];
        }
        a.pop_back();
        n--;
        store.clear();
      }
      cout<<sum<<endl;
    }
}


Answer: 1
Problem: 2062C - Cirno and Operations
Language: c++23 

Code 1:
#include <iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        long long int arr[n];
        long long int ans=0;

        for(int i=0;i<n;i++){
            cin>>arr[i];
            ans +=arr[i];
        }
        if(n==1){
            cout<<arr[0]<<"\n";
            continue;
        }
        ans = abs(ans);
        for(int i=0;i<n-1;i++){
            int j=i;
            long long int pos_ans =0;
            for(int h=0;h<n-1-j;h++){
                arr[h]= arr[h+1] - arr[h];
                pos_ans += arr[h];
            }
            pos_ans = abs(pos_ans);
            ans = max(ans,pos_ans);
        }
        cout<<ans<<"\n";
    }
}

Code 2:
#include <iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        long long int arr[n];
        long long int ans=0;

        for(int i=0;i<n;i++){
            cin>>arr[i];
            ans +=arr[i];
        }
        if(n==1){
            cout<<arr[0]<<"\n";
            continue;
        }
        
        for(int i=0;i<n-1;i++){
            int j=i;
            long long int pos_ans =0;
            for(int h=0;h<n-1-j;h++){
                arr[h]= arr[h+1] - arr[h];
                pos_ans += arr[h];
            }
            pos_ans = abs(pos_ans);
            ans = max(ans,pos_ans);
        }
        cout<<ans<<"\n";
    }
}

Answer: 2