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

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

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

void run_case(){
      int n;
      cin>>n;
      vector<ll>a(n+1);
      for(int i=1;i<=n;i++){
        cin>>a[i];
      }
      ll ans=LLONG_MIN;
      int curr=n;
      for(int i=1;i<=n;i++){
          ll sum=0;
          for(int j=1;j<=curr;j++){
            sum+=a[j];
          }
          if(i==1){
            ans=max(ans,sum);
          }
          else{
            ans=max(ans, max(sum, -sum));
          }
          for(int j=1;j<curr;j++){
            a[j]=a[j+1]-a[j];
          }
          curr--;
      }
      cout<<ans<<endl;
      
      





}

int main(){
      cin.tie(0)->sync_with_stdio(0);
       int tt;
       cin>>tt;
       
       while(tt--){
           run_case();
       }
}

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

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

void run_case(){
      int n;
      cin>>n;
      vector<int>a(n+1);
      for(int i=1;i<=n;i++){
        cin>>a[i];
      }
      ll ans=LLONG_MIN;
      int curr=n;
      for(int i=1;i<=n;i++){
          ll sum=0;
          for(int j=1;j<=curr;j++){
            sum+=a[j];
          }
          if(i==1){
            ans=max(ans,sum);
          }
          else{
            ans=max(ans, max(sum, -sum));
          }
          for(int j=1;j<curr;j++){
            a[j]=a[j+1]-a[j];
          }
          curr--;
      }
      cout<<ans<<endl;
      
      





}

int main(){
      cin.tie(0)->sync_with_stdio(0);
       int tt;
       cin>>tt;
       
       while(tt--){
           run_case();
       }
}

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

Code 1:
for _ in range(int(input())):

    n = int(input())
    arr = list(map(int, input().split()))

    ans = sum(arr)

    while len(arr) > 1:
        arr = [arr[i+1]-arr[i] for i in range(len(arr)-1)]
        ans = max(ans, abs(sum(arr)))
    
    print(ans)

Code 2:
for _ in range(int(input())):

    n = int(input())
    arr = list(map(int, input().split()))

    ans = sum(arr)

    for i in range(n-1, -1, -1):
        if i > 1:
            arr = [arr[j+1]-arr[j] for j in range(i)]
            ans = max(ans, abs(sum(arr)))
    print(ans)

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

Code 1:
// 主函数，程序的入口点
#include <bits/stdc++.h>
// #define int long long
#define ios ios::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
const int N = 2e5 + 7, modd = 998244353, mod = 1e9 + 7, inf = 0x3f3f3f;
#define endl '\n'
#define ll long long
#define int long long 
signed main()
{
    // 定义变量 t，用于存储测试数据的组数
    int t;
    // 从标准输入读取测试数据的组数
    cin >> t;
    // 循环处理每组测试数据
    while (t--)
    {
        // 定义变量 n，用于存储当前测试数据中序列的长度
        int n;
        // 从标准输入读取序列的长度
        cin >> n;
        // 定义数组 a，用于存储序列的元素
        vector<int> a(n + 1);
        // 循环读取序列的每个元素，并存储在数组 a 中
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        // 初始化当前序列的长度为 n
        int now = n;
        // 初始化最终结果为一个极小值
        long long ans = -1e18;
        // 主循环，控制处理的轮数
        for (int i = 1; i <= n; i++)
        {
            // 初始化当前序列的和为 0
            long long sum = 0;
            // 计算当前序列的和
            for (int j = 1; j <= now; j++)
                sum = (sum + a[j]);
            // 如果是第一轮处理，直接更新 ans 为 ans 和 sum 中的较大值
            if (i == 1)
                ans = max(ans, sum);
            // 否则，更新 ans 为 ans、sum 和 -sum 中的最大值
            else
                ans = max(ans, max(sum, (-sum)));
            // 对当前序列进行差分操作
            for (int j = 1; j < now; j++)
                a[j] = (a[j + 1] - a[j]);
            // 序列长度减 1
            now--;
        }
        // 输出最终的最大值
        cout << ans << endl;
    }
    // 程序正常结束
    return 0;
}

Code 2:
// 主函数，程序的入口点
#include <bits/stdc++.h>
// #define int long long
#define ios ios::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
const int N = 2e5 + 7, modd = 998244353, mod = 1e9 + 7, inf = 0x3f3f3f;
#define endl '\n'
#define ll long long
int main()
{
    // 定义变量 t，用于存储测试数据的组数
    int t;
    // 从标准输入读取测试数据的组数
    cin >> t;
    // 循环处理每组测试数据
    while (t--)
    {
        // 定义变量 n，用于存储当前测试数据中序列的长度
        int n;
        // 从标准输入读取序列的长度
        cin >> n;
        // 定义数组 a，用于存储序列的元素
        vector<int> a(n + 1);
        // 循环读取序列的每个元素，并存储在数组 a 中
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        // 初始化当前序列的长度为 n
        int now = n;
        // 初始化最终结果为一个极小值
        long long ans = -1e18;
        // 主循环，控制处理的轮数
        for (int i = 1; i <= n; i++)
        {
            // 初始化当前序列的和为 0
            long long sum = 0;
            // 计算当前序列的和
            for (int j = 1; j <= now; j++)
                sum = (sum + a[j]);
            // 如果是第一轮处理，直接更新 ans 为 ans 和 sum 中的较大值
            if (i == 1)
                ans = max(ans, sum);
            // 否则，更新 ans 为 ans、sum 和 -sum 中的最大值
            else
                ans = max(ans, max(sum, (-sum)));
            // 对当前序列进行差分操作
            for (int j = 1; j < now; j++)
                a[j] = (a[j + 1] - a[j]);
            // 序列长度减 1
            now--;
        }
        // 输出最终的最大值
        cout << ans << endl;
    }
    // 程序正常结束
    return 0;
}

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

Code 1:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 1e18;
void solve(){
    int n;cin >> n;
    vector<int>a(n+1,0);
    for(int i = 1;i <= n;i++) cin >> a[i];
    if(n==1){
        cout<<a[1]<<"\n";
        return ;
    }
    LL ans = -INF;
    for(int i = 1;i <= n;i++){
        LL sum = 0;
        for(int j = 1;j <= n-i+1;j++) sum += a[j];
        ans = max(ans,max(sum,-sum));
        for(int j = 1;j <= n-i;j++) a[j] = a[j+1] - a[j];
    }
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int T = 1;cin >> T;
    while(T-- )solve();
    return 0;
}

Code 2:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 1e18;
void solve(){
    int n;cin >> n;
    vector<LL>a(n+1,0);
    for(int i = 1;i <= n;i++) cin >> a[i];
    if(n==1){
        cout<<a[1]<<"\n";
        return ;
    }
    LL ans = -INF;
    for(int i = 1;i <= n;i++){
        LL sum = 0;
        for(int j = 1;j <= n-i+1;j++) sum += a[j];
        if(i==1)ans = max(ans,sum);
        else ans = max(ans,max(sum,-sum));
        for(int j = 1;j <= n-i;j++) a[j] = a[j+1] - a[j];
    }
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int T = 1;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 pb push_back
#define all(a) (a).begin(), (a).end()
#define X(a) (a).begin(), (a).begin()
#define ii pair<int,int>
typedef long long int ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;cin>>n;
        vector<ll>a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        if(n==1){
            cout<<a[0]<<endl;continue;
        }
        ll res=INT_MIN;
        int k=1;
        while(n!=1){
            ll x=0;
            for(int i=0;i<n;i++) x+=a[i];
            n--;
            for(int i=0;i<n;i++) a[i]=a[i+1]-a[i];
            if(!k) res=max(res,abs(x));
            else{
                res=max(res,x);k=0;
            }
            
        }
        cout<<max(res,abs(a[0]))<<endl;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define X(a) (a).begin(), (a).begin()
#define ii pair<int,int>
typedef long long int ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;cin>>n;
        vector<ll>a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        if(n==1){
            cout<<a[0]<<endl;continue;
        }
        ll res=INT_MIN;
        int k=1;
        while(n!=1){
            ll x=0;
            for(int i=0;i<n;i++) x+=a[i];
            n--;
            for(int i=0;i<n;i++) a[i]=a[i+1]-a[i];
            if(!k) res=max(res,abs(x));
            else res=max(res,x);
            k--;
        }
        cout<<max(res,abs(a[0]))<<endl;
    }
}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int sum(vector<int>&v){
    int tot = 0;
    for(int i = 1;i < v.size();i++)
        tot += v[i] - v[i - 1] ;
    return tot;
}
int sumall(vector<int>&v){
    int sum = 0;
    for(int i = 0;i < v.size();i++){
        sum +=v[i];
    }
    return sum;
}
void _()
{
    int n; cin >> n;
    vector<int>v(n);
    for(int i = 0;i < n;i++)
        cin >> v[i];
    int res = -1e10;
    while(!v.empty()){
        res = max(res,sumall(v));
        vector<int>a = v,b = v;
        reverse(a.begin(),a.end());
        if(sum(a) > sum(b)){
            reverse(v.begin(),v.end());
        }
        for(int i = 0;i < v.size() - 1;i++){
            v[i] = v[i + 1] - v[i];
        }
        v.pop_back();
    }
    cout << res << endl;
}
signed main()
{
    int t = 1;cin >> t;
    while(t--)
    {
        _();
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int sum(vector<int>&v){
    int tot = 0;
    for(int i = 0;i < v.size() - 1;i++)
        tot += v[i] - v[i + 1] ;
    return tot;
}
int sumall(vector<int>&v){
    int sum = 0;
    for(int i = 0;i < v.size();i++){
        sum +=v[i];
    }
    return sum;
}
void _()
{
    int n; cin >> n;
    vector<int>v(n);
    for(int i = 0;i < n;i++)
        cin >> v[i];
    int res = -1e10;
    while(!v.empty()){
        res = max(res,sumall(v));
        vector<int>a = v,b = v;
        reverse(a.begin(),a.end());
        if(sum(a) > sum(b)){
            reverse(v.begin(),v.end());
        }
        for(int i = 0;i < v.size() - 1;i++){
            v[i] = v[i + 1] - v[i];
        }
        v.pop_back();
    }
    cout << res << endl;
}
signed main()
{
    int t = 1;cin >> t;
    while(t--)
    {
        _();
    }
    return 0;
}


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

Code 1:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 50+5;
ll T,n,a[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(false),cout.tie(false);
	cin>>T;
	while(T--){
		cin>>n;
		ll sum=0,maxx=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		maxx=sum;
		for(int i=2;i<=n;i++){
			sum=0;
			for(int j=n;j>=i;j--){
				a[j]=a[j]-a[j-1];
				sum+=a[j];
			}
			maxx=max(maxx,(sum<0 ? -sum : sum));
		}
		cout<<maxx<<endl;
	}
	return 0;
}


Code 2:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 50+5;
ll T,n,a[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	cin>>T;
	while(T--){
		cin>>n;
		ll sum=0,maxx=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		maxx=sum;
		for(int i=2;i<=n;i++){
			sum=0;
			for(int j=n;j>=i;j--){
				a[j]=a[j]-a[j-1];
				sum+=a[j];
			}
			maxx=max(maxx,(sum<0 ? -sum : sum));
		}
		cout<<maxx<<endl;
	}
	return 0;
}

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

Code 1:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

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

    return rep_a;

}

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

        sum += a[i];
    }

    return abs(sum);

}

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;
        sum = sum_array(a);

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

        }

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

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

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

Code 1:
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

// Convert a vector of ints into a string key for memoization.
string vecToKey(const vector<int>& arr) {
    // We join numbers with a comma.
    string key;
    for (int x : arr) {
        key += to_string(x) + ",";
    }
    return key;
}

unordered_map<string, ll> memo;

ll F(const vector<int>& arr) {
    // Casos base
    string key = vecToKey(arr);
    if (memo.count(key))
        return memo[key];       // memoizacao
    
    if (arr.size() == 1)
        return memo[key] = arr[0];

    // Recursao    
    // Soma do original
    ll sum1 = 0;
    for (int x : arr)
        sum1 += x;
    
    // Soma do invertido
    vector<int> rev(arr);
    reverse(rev.begin(), rev.end());
    ll sum2 = 0;
    for (int x : rev)
        sum2 += x;
    
    // Sequencia original
    vector<int> diff1;
    for (size_t i = 0; i < arr.size()-1; i++){
        diff1.push_back(arr[i+1] - arr[i]);
    }
    
    // Sequencia invertida
    vector<int> diff2;
    for (size_t i = 0; i < rev.size()-1; i++){
        diff2.push_back(rev[i+1] - rev[i]);
    }
    
    ll ans = max({ sum1, sum2, F(diff1), F(diff2) });
    memo[key] = ans;
    return ans;
}
 
int main(){
    BOOST
    
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        memo.clear();
        cout << F(arr) << "\n";
    }
    return 0;
}


Code 2:
/**
 * SUGERIDO:
 */

#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

int main(){
    BOOST
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<ll> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        
        // Se n = 1, nao precisa processar
        if(n == 1){
            cout << arr[0] << "\n";
            continue;
        }
        
        // Se k = 0: nao calcula subtracoes
        ll sum0 = 0;
        for (ll x : arr)
            sum0 += x;
        ll best = sum0; // Nota, nao inverter para k=0
        
        vector<ll> current = arr;
        
        // Para cada k de 1 ate n-1, aplicar operacao 2 ("Replace the sequence with its difference sequence")
        for (int k = 1; k < n; k++){
            vector<ll> next;
            for (int i = 0; i < (int)current.size() - 1; i++){
                next.push_back(current[i+1] - current[i]);
            }
            // Soma da diferenca
            ll s = 0;
            for (ll x : next)
                s += x;
            
            // Para k >= 1 ver com o sinal trocado (se s negativo, inversao da positivo - llabs)
            best = max(best, llabs(s));
            
            // Proxima iteracao
            current = next;
        }
        
        cout << best << "\n";
    }
    return 0;
}


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

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
int a[1000005],n;

void solve() {
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ans += a[i];
	}
	if (n == 1) {
		cout << ans << endl;//不能进行1，2操作
        return;
	}
	while (n) {
		n--;
		for (int i = 1; i <= n; i++) {
			a[i] = a[i + 1] - a[i];//2操作
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) sum += a[i];
		ans = max(ans, max(sum, -sum));//是否进行1操作
	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int tt;
	cin >> tt;
	while (tt--)
		solve();
	return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
int a[1000005],n;

void solve() {
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ans += a[i];
	}
	if (n == 1) {
		cout << ans << endl;//不能进行1，2操作
	}
	while (n) {
		n--;
		for (int i = 1; i <= n; i++) {
			a[i] = a[i + 1] - a[i];//2操作
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) sum += a[i];
		ans = max(ans, max(sum, -sum));//是否进行1操作
	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int tt;
	cin >> tt;
	while (tt--)
		solve();
	return 0;
}

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

Code 2:
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
long long fac(vector<int> &dp,int n,int i,int a){
    if(n<=i){
        return 1;
    }
    
    return n*fac(dp,n-1,i,a-1)/a;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        bool f=false;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
            if(arr[i]<=0){
               f = true; 
            }
        }
        if(n==1){
            cout<<arr[0]<<endl;
            continue;
        }
        vector<int> dp(n+1);
        for(auto x:dp)x=-1;
        long long sum=0;
        if(f){
        for(int i=0;i<n;i++){
            sum += fac(dp,n-1,n-i-1,i)*(arr[i])*pow(-1,i);
        }
        }
        else{
            for(int i=0;i<n;i++){
                sum+=arr[i];
            }
        }
        cout<<abs(sum)<<endl;
    
    }
    return 0;
}

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

Code 1:
import sys

input = lambda: sys.stdin.readline().rstrip("\r\n")

INF = int(1e18)


def solve():
    N = int(input())
    a = [int(v) for v in input().split()]
    ans = sum(a)
    while len(a) > 1:
        ans = max(ans, abs(a[0] - a[-1]))
        a = [a[i] - a[i - 1] for i in range(1, len(a))]
    return ans


for _ in range(int(input())):
    # solve()
    print(solve())
    # print("YES" if solve() else "NO")


Code 2:
import sys

input = lambda: sys.stdin.readline().rstrip("\r\n")

INF = int(1e18)


def solve():
    N = int(input())
    a = [int(v) for v in input().split()]
    ans = -INF
    while len(a) > 1:
        ans = max(ans, abs(sum(a)))
        a = [a[i] - a[i - 1] for i in range(1, len(a))]
    ans = max(ans, abs(a[0]))
    return ans


for _ in range(int(input())):
    # solve()
    print(solve())
    # print("YES" if solve() else "NO")


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

Code 1:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
void solve(){
	int n;
	cin >> n;
	vector<int>a(n+1);
	for(int i=1;i<=n;i++)cin >> a[i];
	if(n==1){
		cout << a[1] << endl;
		return ;
	}
	int ans=-1e9;
	for(int i=n-1;i>=1;i--){
		int  t=0;
		for(int j=1;j<=i+1;j++)t+=a[j];
		if(i==n-1)ans=max({ans,t});
		else{
			ans=max({ans,-t,t});
		}
		for(int j=1;j<=i;j++){
			a[j]=a[j+1]-a[j];
		}
	}	
	cout << max({ans,a[1],-a[1]}) << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int _=1;
	cin >> _;
	while(_--)
		solve();
}

Code 2:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
void solve(){
	int n;
	cin >> n;
	vector<int>a(n+1);
	for(int i=1;i<=n;i++)cin >> a[i];
	if(n==1){
		cout << a[1] << endl;
		return ;
	}
	int ans=-1e9;
	for(int i=n-1;i>=1;i--){
		int  t=0;
		for(int j=1;j<=i+1;j++)t+=a[j];
		ans=max({ans,t});
		for(int j=1;j<=i;j++){
			a[j]=a[j+1]-a[j];
		}
	}	
	cout << max({ans,a[1],-a[1]}) << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int _=1;
	cin >> _;
	while(_--)
		solve();
}

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

Code 1:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int &i:a) 
    {
        cin >> i;
        sum += i;
    }
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i)
    {
        for(int j=0;j<a.size()-1;++j)
            a[j]=a[j+1]-a[j];
        a.pop_back();
        int temp = 0;
        for(int j=0;j<a.size();++j)
            temp+=a[j];
        if(abs(temp)>abs(sum) )
        {
            sum=temp;
        }
    }
    cout<<abs(sum)<<endl;
}

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


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
	long long a[1010];
	int n;
	cin >> n;
	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;
}

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


Answer: 2