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

Code 1:
// Created by Rishi Sharma (@rishisharmapro) on 05-02-2025 at 13:10
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    ll maxSum = accumulate(a, a+n, 0ll), sum = 0;
    
    while(--n) {
        sum = 0;
        for(int i = 0; i < n; i++) {
            a[i] = a[i+1] - a[i];
            sum += a[i];
        }
        // cout << sum << " ";
        sum = max(sum, -1 * sum);
        maxSum = max(maxSum, sum);
    }
    maxSum = max(maxSum, (ll)a[0]);

    cout << maxSum << endl;
}

int main() {
    // problem: https://codeforces.com/contest/2062/problem/C
    fast_io;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Code 2:
// Created by Rishi Sharma (@rishisharmapro) on 05-02-2025 at 13:10
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    ll maxSum = accumulate(a, a+n, 0ll), sum = 0;
    
    while(--n) {
        sum = 0;
        for(int i = 0; i < n; i++) {
            a[i] = a[i+1] - a[i];
            sum += a[i];
        }
        // cout << sum << " ";
        sum = max(sum, -1 * sum);
        maxSum = max(maxSum, sum);
    }
    maxSum = max(maxSum, (ll)a[0]);

    cout << maxSum << endl;
}

int main() {
    // problem: https://codeforces.com/contest/2062/problem/C
    fast_io;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

Code 1:
/*Les do some thikr:
سُبْحَانَ ٱللَّٰهِ
ٱلْحَمْدُ لِلَّٰهِ
 الله أكبر
أَسْتَغْفِرُ ٱللَّٰهَ
سُبْحَانَ اللَّهِ وَبِحَمْدِهِ، سُبْحَانَ اللَّهِ العَظِيم
 لَا حَوْلَ وَلَا قُوَّةَ إِلَّا بِٱللَّٰهِ ٱلْعَلِيِّ ٱلْعَظِيمِ
لا إله إلا الله
and durood
اللَّهُمَّ بَارِكْ عَلَى مُحَمَّدٍ، وَعَلَى آلِ مُحَمَّدٍ، كَمَا بَارَكْتَ عَلَى إِبْرَاهِيمَ، وَعَلَى آلِ إِبْرَاهِيمَ، إِنَّكَ حَمِيدٌ مَجِيدٌ
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long

//bitset<100001>a;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t=1;
cin>>t;

    while(t--)
    {
      ll n,i,x,f=0,sum=0,mx;
      cin>>n;
     vector<ll>v,v1;
      for(i=0; i<n; i++)
      {
          cin>>x;
         v.push_back(x);
         
         sum+=x;
      }
     mx=sum;
      while(n--)
      { sum=0,f=0;
          reverse(v.begin(),v.end());
          for(i=1; i<v.size(); i++)
          { x=v[i]-v[i-1];
         
          sum+=x;
              v1.push_back(x);
              f=1;
          }
          
          v=v1;
          v1.clear();
          if(f)
         mx=max(mx,sum);
      }
     // cout<<v[0]<<" ";
   
     
   cout<<mx<<"\n";
    }
    
 
 
return 0;
}

Code 2:
/*Les do some thikr:
سُبْحَانَ ٱللَّٰهِ
ٱلْحَمْدُ لِلَّٰهِ
 الله أكبر
أَسْتَغْفِرُ ٱللَّٰهَ
سُبْحَانَ اللَّهِ وَبِحَمْدِهِ، سُبْحَانَ اللَّهِ العَظِيم
 لَا حَوْلَ وَلَا قُوَّةَ إِلَّا بِٱللَّٰهِ ٱلْعَلِيِّ ٱلْعَظِيمِ
لا إله إلا الله
and durood
اللَّهُمَّ بَارِكْ عَلَى مُحَمَّدٍ، وَعَلَى آلِ مُحَمَّدٍ، كَمَا بَارَكْتَ عَلَى إِبْرَاهِيمَ، وَعَلَى آلِ إِبْرَاهِيمَ، إِنَّكَ حَمِيدٌ مَجِيدٌ
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long

//bitset<100001>a;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t=1;
cin>>t;

    while(t--)
    {
      ll n,i,x,f=0,sum=0,mx;
      cin>>n;
     vector<ll>v,v1;
      for(i=0; i<n; i++)
      {
          cin>>x;
         v.push_back(x);
         
         sum+=x;
      }
     mx=sum;
      while(n--)
      { sum=0,f=0;
        
          for(i=1; i<v.size(); i++)
          { x=v[i]-v[i-1];
         
          sum+=x;
              v1.push_back(x);
              f=1;
          }
          
          v=v1;
          v1.clear();
          if(f)
         mx=max({mx,sum,-sum});
      }
     // cout<<v[0]<<" ";
   
     
   cout<<mx<<"\n";
    }
    
 
 
return 0;
}

Answer: 2
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;
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];an=max(an,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;
}


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


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

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 5e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, a[N];

void solve()
{
    vector<int> f1, f2;
    int ans = -1e15;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        f1.push_back(x);
    }
    if (n == 1) {
        cout << f1[0] << endl;
        return;
    }
    int res = 0;
    for (auto x : f1) {
        res += x;
    }
    ans = max(ans, max(res, -res));
    while (f1.size() > 1) {
        f2.clear();
        for (int i = 1; i < f1.size(); i += 1) {
            f2.push_back(f1[i] - f1[i - 1]);
        }
        res = 0;
        for (auto x : f2) res += x;
        ans = max(ans, max(res, -res));
        f1 = f2;
    }
    cout << ans << endl;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 5e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n;

void solve()
{
    vector<int> f1, f2;
    int ans = -1e15;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        f1.push_back(x);
    }
    if (n == 1) {
        cout << f1[0] << endl;
        return;
    }
    int res = 0;
    for (auto x : f1) {
        res += x;
    }
    ans = max(ans, res);
    while (f1.size() > 1) {
        f2.clear();
        for (int i = 1; i < f1.size(); i += 1) {
            f2.push_back(f1[i] - f1[i - 1]);
        }
        res = 0;
        for (auto x : f2) res += x;
        ans = max(ans, max(res, -res));
        f1 = f2;
    }
    cout << ans << endl;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/

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

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

using namespace std;
int main() {
  int num_tests;
  cin >> num_tests;

  for (int t = 0; t < num_tests; ++t) {
    int n;
    cin >> n;
    vector<int> a;
    int s = 0;
    for (int i = 0; i < n; ++i) {
      int ai;
      cin >> ai;
      s += ai;
      a.push_back(ai);
    }

    vector<int> b;
    while (a.size() >= 2) {
      int next_s = 0;
      if (a[0] > a[a.size() - 1]) {
        reverse(a.begin(), a.end());
      }
      for (int i = 1; i < a.size(); ++i) {
        next_s += a[i] - a[i - 1];
        b.push_back(a[i] - a[i - 1]);
      }
      if (next_s > s) {
        s = next_s;
      }
      a = b;
      b.clear();
    }
    printf("%d\n", s);
  }
}


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

using namespace std;
int main() {
  int num_tests;
  cin >> num_tests;

  for (int t = 0; t < num_tests; ++t) {
    int n;
    cin >> n;
    vector<long long> a;
    long long s = 0;
    for (int i = 0; i < n; ++i) {
      long ai;
      cin >> ai;
      s += ai;
      a.push_back(ai);
    }

    vector<long long> b;
    while (a.size() >= 2) {
      long long next_s = 0;
      if (a[0] > a[a.size() - 1]) {
        reverse(a.begin(), a.end());
      }
      for (int i = 1; i < a.size(); ++i) {
        next_s += a[i] - a[i - 1];
        b.push_back(a[i] - a[i - 1]);
      }
      if (next_s > s) {
        s = next_s;
      }
      a = b;
      b.clear();
    }
    printf("%lld\n", s);
  }
}


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

Code 1:
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=1;i<=n;i++){
            cin>>arr[i];
        }
        if(n==1){
            cout<<arr[1]<<endl;
            continue;
        }
        int temp=n;
        long long ans = -1e18;
        
        for(int i=1;i<=n;i++){
            long long sum=0;
            for (int i = 1; i <= temp; i++) sum = (sum + arr[i]);
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < temp; i++) arr[i] = (arr[i + 1] - arr[i]);
			temp--;
        }
        
       
        cout<<abs(ans)<<endl;
    
    }
    return 0;
}

Code 2:
#include <iostream>
#include<vector>
#include<cmath>
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];
        }
        if(n==1){
            cout<<arr[1]<<endl;
            continue;
        }
        int temp=n;
        long long ans = -1e18;
        
        for(int i=1;i<=n;i++){
            long long sum=0;
            for (int i = 1; i <= temp; i++) sum = (sum + arr[i]);
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < temp; i++) arr[i] = (arr[i + 1] - arr[i]);
			temp--;
        }
        
       
        cout<<abs(ans)<<endl;
    
    }
    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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n; // Number of test cases
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a ; 
        vector<ll> k(a);
        
        for (int i = 0; i < a; i++) {
            cin >> k[i];
        }
        bool flag = true;
        int size = a;
        ll sum = accumulate(k.begin(),k.end(),0ll);
        // if(size == 2) sum = max(sum,max(k[0] - k[1],k[1] - k[0]));
        // else{
        while(size!=1){
                for(int i = 1;i<size;i++){
                    k[i-1] = k[i] - k[i-1];
                }
                k.pop_back();
                ll curr = accumulate(k.begin(),k.end(),0ll);
                sum = max(sum,abs(curr));
                size--;
            }
        // }
        cout << sum << endl;
    }

    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n; // Number of test cases
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a ; 
        vector<ll> k(a);
        
        for (int i = 0; i < a; i++) {
            cin >> k[i];
        }
        bool flag = true;
        int size = a;
        ll sum = accumulate(k.begin(),k.end(),0ll);
        if(size == 2) sum = max(sum,max(k[0] - k[1],k[1] - k[0]));
        else{
        while(size!=1){
                for(int i = 1;i<size;i++){
                    k[i-1] = k[i] - k[i-1];
                }
                k.pop_back();
                sum = max(sum,abs(k.front() - k.back()));
                size--;
            }
        }
        cout << sum << endl;
    }

    return 0;
}


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

Code 1:
#define SETBIT(x, i) ((x & (1 << i)) != 0)
#define ll long long
#include<bits/stdc++.h>
#define inf LLONG_MAX
#define neg_inf LLONG_MIN
using namespace std ;
void solve(){
  int n ;
  cin>>n ;
  vector<ll>arr(n) ;
  int cntneg=0 ;
  for(int i=0 ; i<n ; i++){
    cin>>arr[i] ;
    if(arr[i]<0)cntneg++;
}
  if(n==1){
    cout<<arr[0]<<endl;
    return ;
  }
  
  ll ans =0 ;
  for(int i=0 ; i<n ; i++)ans+=arr[i] ;
   
  vector<ll>temp = arr ;
  for(int i=0 ; i<n-1 ; i++){
    vector<ll> k ;
     for(int j=1 ; j<temp.size() ; j++){
      k.push_back(temp[j]-temp[j-1]);
    }
    temp = k ;
 
    ll S = 0 ;
    for(int i=0 ; i<k.size();i++)S+=k[i] ;
    ans = max(ans , S) ;
  ans = max(ans,-S) ;
  }
  cout<<ans<<endl;

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

Code 2:
#define SETBIT(x, i) ((x & (1 << i)) != 0)
#define ll long long
#include<bits/stdc++.h>
#define inf LLONG_MAX
#define neg_inf LLONG_MIN
using namespace std ;
void solve(){
  int n ;
  cin>>n ;
  vector<ll>arr(n) ;
  for(int i=0 ; i<n ; i++)cin>>arr[i];
  if(n==1){
    cout<<arr[0]<<endl;
    return ;
  }
  ll ans =accumulate(arr.begin(),arr.end(),0) ;
  
  ans = max(ans , -ans) ;
  vector<ll>temp = arr ;
  for(int i=0 ; i<n ; i++){
    vector<ll> k ;
     for(int j=0 ; j<temp.size()-1 ; j++){
      k.push_back(temp[j+1]-temp[j]);
    }
    temp = k ;
    ll S = accumulate(k.begin(),k.end(),0) ;
    ans = max(ans , S) ;
    ans = max(ans,-S) ;
  }
  cout<<ans<<endl;

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

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

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

#define max(a, b) ((a > b) ? a : b)

using namespace std;

long long a[59];
int tmp[59];

int t;
int n;

long long res = 0;
long long sum;

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

    cin >> t;

    while (t--)
    {
        cin >> n;

        res = LONG_LONG_MIN;

        for (int i = 0; i < n; i++) cin >> a[i];

        int k = n;

        for (int j = 0; j < k; j++)
        {
            sum = 0;

            for (int i = 0; i < n; i++) sum += a[i];

            res = max(res, sum);
            if (k > 1) res = max(res, -sum);
            n--;

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

        cout << res << '\n';
    }

    return 0;
}

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

#define max(a, b) ((a > b) ? a : b)

using namespace std;

long long a[59];
int tmp[59];

int t;
int n;

long long res = 0;
long long sum;

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

    cin >> t;

    while (t--)
    {
        cin >> n;

        res = LONG_LONG_MIN;

        for (int i = 0; i < n; i++) cin >> a[i];

        int k = n;

        for (int j = 0; j < k; j++)
        {
            sum = 0;

            for (int i = 0; i < n; i++) sum += a[i];

            res = max(res, sum);
            if (j > 0) res = max(res, -sum);
            n--;

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

        cout << res << '\n';
    }

    return 0;
}

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

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

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    long long ans = 0;

    for (long long i = 0; i<n ; i++) {ans += a[i];}

    long long start = 0;
    long long len = n;
    while (len > 0) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        }
        sum1 = 0;
        for (long long i = start; i<n ; i++) {sum1 += a[i];}
        ans = max(ans, abs(sum1));
        start++; len--;
    }
    // ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

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

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

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    long long ans = 0;

    for (long long i = 0; i<n ; i++) {ans += a[i];}

    long long start = 0;
    long long len = n;
    while (len > 1) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        }
        sum1 = 0;
        start++;
        for (long long i = start; i<n ; i++) {sum1 += a[i];}
        ans = max(ans, abs(sum1));
         len--;
    }
    // ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

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

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

Code 1:
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);

    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        
        // Step 2: Reverse the sequence
        reverse(seq.begin(), seq.end());
    }

    // The final result, which is the only remaining element
    if(n!=1)
    cout<< max(og,abs(seq[0])) << endl;
    else
        cout << og << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        solve();
    }

    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define ll long long
#define el "\n"
#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define MOD 998244353
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<int> applyDifference(const vector<int>& seq) {
    vector<int> diffSeq;
    for (int i = 1; i < seq.size(); ++i) {
        diffSeq.push_back(seq[i] - seq[i-1]);
    }
    return diffSeq;
}

void solve() {
    int n;
    cin >> n;
    
    vi seq(n);
    for(int i=0;i<n;i++){
        cin >> seq[i];
    }
    int og = accumulate(all(seq),0ll);
    int ans = og;
    while (seq.size() > 1) {
        // Step 1: Apply difference operation
        seq = applyDifference(seq);
        ans = max(ans,abs(accumulate(all(seq),0ll)));
    }

    // The final result, which is the only remaining element
        cout << max(og,ans) << el;
}

signed main() {
    OrganicBot;
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        solve();
    }

    return 0;
}

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

Code 1:
import sys
data = sys.stdin.read().splitlines()

line = 2
while (line < len(data)):
    arr = list(map(int, data[line].split()))
    # print("arr=", arr)
    new_arr = arr
    diff = sum(arr)
    if len(arr) == 2:
        diff = max(abs(arr[0]-arr[1]), diff)
    else:
        for i in range(len(arr)-1):
            new_arr = [new_arr[i+1]-new_arr[i] for i in range(len(new_arr)-1)]
            if diff < abs(new_arr[0] - new_arr[-1]):
                diff = abs(new_arr[0] - new_arr[-1])
            # print(new_arr, "...diff=", diff)
    print(diff)
    line += 2

Code 2:
import sys
data = sys.stdin.read().splitlines()

line = 2
while (line < len(data)):
    arr = list(map(int, data[line].split()))
    new_arr = arr
    diff = sum(arr)
    # print(arr, "...diff=", diff)
    if len(arr) == 2:
        diff = max(abs(arr[0]-arr[1]), diff)
    elif len(arr) > 2:
        for i in range(len(arr)-2):
            new_arr = [new_arr[i+1]-new_arr[i] for i in range(len(new_arr)-1)]
            diff = max(abs(new_arr[0]-new_arr[-1]), diff, abs(sum(new_arr)))
            # print(new_arr, "...diff=", diff)
    print(diff)
    line += 2

Answer: 2