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

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

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

  i64 ans = accumulate(a.begin(), a.end(), 0LL);
  while (a.size() > 1) {
    vector<i64> b;
    int size = a.size();
    for (int i = 1; i < size; ++i) {
      b.push_back(a[i] - a[i-1]);
    }
    a = std::move(b);
    i64 new_sum = accumulate(a.begin(), a.end(), 0LL);
    ans = max(ans, abs(new_sum));
  }
  cout << ans << endl;
}

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

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


Solution 2 (runtime: 77 ms):
#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;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 327 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 4e18;
const int N = 2e5 + 5;

int n, m;

void solve(){
	cin >> n >> m;
	multiset<ll> st;
	for(int i = 1;i <= n; ++ i){
		ll x;cin >> x;
		st.insert(x);
	}
	priority_queue<ll, vector<ll>, greater<ll> > pq;
	for(int i = 1;i <= m; ++ i){
		ll x;cin >> x;
		pq.push(x);
	}
	while(pq.size()){
		if(st.size() == 0){
			cout << "No" << '\n';
			return;
		}
		ll x = pq.top();pq.pop();
		if(st.count(x)){
			auto p = st.find(x);
			st.erase(p);
		}else{
			if(x == 1){
				cout << "No" << '\n';
				return;
			}
			ll y1 = x / 2, y2 = x - y1;
			pq.push(y1), pq.push(y2);
		}
	}
	if(st.size())cout << "No" << '\n';
	else cout << "Yes" << '\n';
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _ = 1;cin >> _;
	while(_ --){
		solve();
	}
	return 0;
}
/*



*/

Solution 2 (runtime: 312 ms):
#include<bits/stdc++.h>



using namespace std;

typedef long long ll;

typedef long double ld;

#define pb push_back

#define dbg(x) //cerr<<#x<<": "<<x<<"\n";

map<ll,int>mp;

bool ok(ll x){

    if(mp.count(x) && mp[x]>0){

        mp[x]--;

        return true;

    }

    if(x==1){

        return false;

    }

    if(ok(x/2)&&ok((x+1)/2)){

        return true;

    }

    return false;

}

void code(){

    mp.clear();

    int n,m;

    cin>>n>>m;

    ll a[n],b[m];

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

        cin>>a[i];

        mp[a[i]]++;

    }

    for(int i=0;i<m;i++){

        cin>>b[i];

    }

    for(int i=0;i<m;i++){

        if(!ok(b[i])){

            cout<<"No\n";

            mp.clear();

            return;

        }

    }

    for(auto it:mp){

        if(it.second>0){

            cout<<"No\n";

            mp.clear();

            return;

        }

    }

    cout<<"Yes\n";

    mp.clear();

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //cout.tie(NULL);

    cout.precision(10);

    cout<<fixed;

    int t=1;

    cin>>t;

    for(int i=1;i<=t;i++){

        dbg("case"+to_string(i));

        //cout<<"Case "<<i<<":\n";

        code();

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define ld long double

#define mod 1000000007

#define modd 998244353

#define pb push_back

#define Yes cout<<"YES\n"

#define No cout<<"NO\n"

#define ff first

#define ss second

#define vi vector<long long>

#define pii pair<long long, long long>

#define all(x) x.begin(),x.end()

#define rall(x) x.rbegin(),x.rend()

const int inf = 2e18;

vector<pii> directions{ {0,1}, {1,0}, {0,-1}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1} };

void print(int arr[],int n,string label="") {cout<<label;for(int i=0;i<n;i++) cout<<arr[i]<<" ";cout<<"\n";}

void print(vector<int> v,string label="") {cout<<label;for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<"\n";}

int modPow(int a,int b,int p) {int ans=1;while(b>0){if((b&1)==1)ans=ans*a%p;a=a*a%p;b>>=1;}return ans;}

int modDiv(int a,int b,int p) {return a * modPow(b,p-2,p) % p;}

bool isPow2(int n) {return (n>0 && (n&(n-1)) == 0);}

int power(int a,int b) {int ans=1;while(b>0){if((b&1)==1)ans=ans*a;a=a*a;b>>=1;}return ans;}

int squareroot(int n) {int s=0,e=n;int ans;while(s<=e){int m=(s + e)/2;if(m*m<=n){s=m+1;ans=m;}else{e=m-1;}}return ans;}

void solve(int testcase)

{

    #define TESTCASES

    string s;

    cin>>s;

    int n = s.size();

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

        int mx = 0, ind=0;

        for(int j=0;j<min(n-i,9ll);j++) {

            int x = s[i+j] - '0' - j;

            if(x > mx && x > 0) {

                mx = x;

                ind = j;

            }            

        }

        for(int j=i+ind;j>i;j--) {

            s[j] = s[j-1];

        }

        cout<<mx;

    }

    cout<<'\n';

}

signed main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



    int t=1;

    #ifdef TESTCASES

    cin>>t;

    #endif

    for(int i=1;i<=t;i++)

    {

        solve(i);

    }

    return 0;

}



Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;

#define int long long int



void solve() {

    string str; cin>>str;

    int len = str.size();

    for(int i=0; i<len-1; i++) {

        int max = str[i]-'0', max_index=i;

        for(int j = i+1; j<len&&j<i+9; j++) {

            if(str[j]-'0'-(j-i)>max) {

                max = str[j]-'0'-(j-i);

                max_index = j;

            }

        }

        // char temp = str[i];

        for(int j=max_index; j>i; j--) {

            swap(str[j], str[j-1]);

            str[j-1]--;

        }

        // str[i] = ('0'+max);

        // str[max_index] = temp;

    }

    cout<<str<<"\n";

    return;

}

signed main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t; cin>>t;

    while(t--){

        solve();

    }

    return 0;

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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;


void solver() {
    long long n; cin >> n;
    vector<long long> vec(n);
    for(auto &ele: vec) cin >> ele;
    long long maxi = -99999999999, times = 0;

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

    while(times < n) {
        long long sum = 0;
        for(long long i = 0; i < n - times; i++) {
            sum += vec[i];
        }
        maxi = max(sum, maxi);
        if(times > 0) maxi = max(maxi, -sum);
        for(long long i = 0; i < n - times - 1; i++) {
            vec[i] = vec[i + 1] - vec[i];
        }
        times++;
    }

    cout << maxi << "\n";
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); int input = 1;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // freopen("outofplace.in", "r", stdin);
    // freopen("outofplace.out", "w", stdout);
    cin >> input;
    while(input--)
        solver();
}

Solution 2 (runtime: 62 ms):
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 55;
long long a[maxn];
void work() {
	memset(a, 0, sizeof a);
	long long n,sum=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (n == 1) {
		cout << a[1] << endl;
		return;
	}
	int k = n;
	while (k) {
	 long long ans = a[k] - a[1];
		sum = max(abs(ans), sum);
		for (int i = 1; i < k; i++)a[i] = a[i + 1] - a[i];
		k--;
	}
	cout << sum << endl;
	return;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int testcase;
	cin >> testcase;
	while (testcase--) {
		work();
	}
	
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		string b;
		cin >> b;
		int jmlh = 0, dua = 0, tiga = 0;
		for ( int i = 0; i < b.length(); i++) {
			jmlh += (b[i] - '0');
			if ( b[i] == '2')
				dua++;
			else if ( b[i] == '3')
				tiga++;
		}

		while (true) {
			if ( jmlh % 9 == 0) {
				cout << "YES" << '\n';
				//	cout << jmlh << "JML" << '\n' ;
				break;
			} else if ( dua > 0 || tiga > 0) {
				if ((dua <= 0 || jmlh % 9 == 6 || jmlh % 9 < 4 ) && tiga > 0 ) {
					tiga--;
					jmlh += 6;
					//	cout << "tambah 3"  << jmlh << '\n';
				} else if ( dua > 0) {
					jmlh += 2;
					dua --;
				}//cout << "tambah dua"  << jmlh << '\n';

			} else {
				cout << "NO" << '\n';
				break;
			}




		}




	}
}

Solution 2 (runtime: 77 ms):
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

int main(void) {

	int t; cin >> t;

	while (t--) {

		string s; cin >> s;

		long long all=0,num2=0,num6=0;

		for (int i = 0; i < s.size(); i++) {

			if (s[i] == '2') num2++;

			else if (s[i] == '3') num6++;

			all += (s[i] - '0');

		}

		int len = all % 9;

		if (len == 0) cout << "Yes" << endl;

		else {

			if (len == 1 && (num2 >= 4 || num2 >= 1 && num6 >= 1 )) cout << "Yes" << endl;

			else if (len == 2 && (num2 >= 8 || num2 >= 5 && num6 >= 1 || num2 >= 2 && num6 >= 2 )) cout << "Yes" << endl;

			else if (len == 3 && (num2 >= 3 || num6 >= 1)) cout << "Yes" << endl;

			else if (len == 4 && (num2 >= 7 || num2 >= 4 && num6 >= 1 || num2 >= 1 && num6 >= 2)) cout << "Yes" << endl;

			else if (len == 5 && (num2 >= 2 )) cout << "Yes" << endl;

			else if (len == 6 && (num2 >= 6 ||  num6 >=2  || num2 >= 3 && num6 >= 1 )) cout << "Yes" << endl;

			else if (len == 7 && (num2 >= 1 )) cout << "Yes" << endl;

			else if (len == 8 && (num2 >= 5 || num2 >= 2 && num6 >= 1 )) cout << "Yes" << endl;

			else cout << "No" << endl;







		}







	}











	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define opt() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll = long long;
#define endl "\n"
#define sz(x) (ll)(x).size()
#define tc int t; cin >> t; for (int _ = 1; _ <= t; _++)
//-------------------------------------------

int32_t main()
{   
    opt();
    
    tc{
        int n; cin >> n; 
        vector<int> v(n);
        for(int i = 0; i < n; i++) cin >> v[i];
        if(is_sorted(v.begin(), v.end())){
            cout << "YES" << endl;
            continue;
        }
        for(int i = 0; i < n - 1; i++){
                int mn = min(v[i], v[i + 1]);
                v[i] -= mn;
                v[i + 1] -= mn;
        }
        if(is_sorted(v.begin(), v.end())) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    
    return 0;
}

Solution 2 (runtime: 421 ms):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int tests;
    cin>>tests;
    for (int z=0;z<tests;z++){
        int size;
        cin>>size;
        vector<int> inputArray;
        for (int i=0;i<size;i++){
            int temp;
            cin>>temp;
            inputArray.push_back(temp);
        }
        bool endCheck = false;
        int i=0;
        while(i<inputArray.size()-1 && !endCheck){
            if (inputArray[i]<=inputArray[i+1]){
                inputArray[i+1]=inputArray[i+1]-inputArray[i];
                inputArray[i]=0;
            }else{
                endCheck =true;
            }
            i++;
        }
        if (endCheck){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>
#include <algorithm>
#include<vector>
#include<unordered_map>
#include<queue>
#include<string>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string str;cin>>str;
        int s=str.size();
        vector<vector<int> > dp(s+1,vector<int>(9,0));
        dp[s][0]=1;
        for(int curr=s-1;curr>=0;curr--){
            int x=str[curr]-'0';
            for(int i=0;i<9;i++){
                if(dp[curr+1][i]==1){dp[curr][(i+x)%9]=1;}
            }
            if(x==2 || x==3){
            for(int i=0;i<9;i++){
                if(dp[curr+1][i]==1){dp[curr][(i+(x*x)%9)%9]=1;}
            }
            }
        }
        if(dp[0][0]==0){cout<<"NO";}
        else{cout<<"yes";}
        cout<<endl;
        }
    return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> dp;

bool knapsack(const string& s, int sumMod9, int pos) {
    if (pos >= s.length()) {
        return (sumMod9 == 0);
    }
    
    if (dp[pos][sumMod9] != -1) {
        return dp[pos][sumMod9];
    }
    
    bool case1 = false, case2 = false;
    int digit = s[pos] - '0';
    
    if (digit <= 3) {
        int newSum = ((sumMod9 - digit + (digit * digit)) % 9 + 9) % 9;
        case1 = knapsack(s, newSum, pos + 1);
    }
    
    case2 = knapsack(s, sumMod9, pos + 1);
    
    return dp[pos][sumMod9] = (case1 || case2);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        string n;
        cin >> n;
        
        int sum = 0;
        for (char c : n) {
            sum = (sum + (c - '0')) % 9;
        }
        
        
        dp.assign(n.length(), vector<int>(9, -1));
        
        if (sum == 0) {
            cout << "YES\n";
            continue;
        }
        
        if (knapsack(n, sum, 0)) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
    
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    test:
    while (tc--) {
        ll l, r; cin >> l >> r;
        
        ll a;
        for (ll i = 31; i >= 0; i--) {
            if ((l & (1 << i)) != (r & (1 << i))) {
                a = (1 << i);
                break;
            }
        }
        
        a = l | (a-1);
        ll b = a+1;
        ll c = (a == l ? r : l);
        cout << a << " " << b<< " " << c << "\n";
    }
}

Solution 2 (runtime: 92 ms):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    int tt;
    cin>>tt;
    while(tt--){
        ll l,r;
        cin>>l>>r;
        int pos=0;
        for(int i=30;i>=0;i--){
            if((l&(1LL<<i))!=(r&(1LL<<i))){
                pos=i;
                break;
            }
        }
        ll a=l|((1<<pos)-1);
        ll b=a+1;
        ll c=r;
        if(a==c||b==c) c--;
        if(a==c||b==c) c--;
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;

#define gc getchar_unlocked

#define fo(i, n) for (long long i = 0; i < n; i++)

#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)

#define ll long long

#define deb(x) cout << #x << "=" << x << endl

#define pb push_back

#define mp make_pair

#define F first

#define S second

#define all(x) x.begin(), x.end()

#define clr(x) memset(x, false, sizeof(x))

#define sortall(x) sort(all(x))

#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)

#define PI 3.1415926535897932384626

#define mod 1000000007

typedef pair<long long, long long> pii;

typedef pair<ll, ll> pl;

typedef vector<long long> 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--)

    {

        //write code here

        string s;

        cin>>s;

        int n=s.length();

        vector<int>digit(n);

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

            digit[i]=s[i]-'0';

        }

        for(int i=1;i<n;i++){

            int j=i;

            while(j>=1 && digit[j]>0 && digit[j]>digit[j-1]+1 ){

                  swap(digit[j],digit[j-1]);

                  digit[j-1]--;

                  if(j>1) j--;

                  else break;

            }

        }

        string ans="";

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

            ans+=to_string(digit[i]);

        }

        cout<<ans<<endl;





    

  

    }

}

  

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>

using namespace std;





void solution() {

    string s;

    cin >> s;

    for(int i = 0; i < s.size(); i++) {

        int ind = INT_MAX;

        int mx = -1;

        int ct = 0;

        for(int j = i; j < min((int)s.size(),i + 10); j++) {

            if(s[j] - '0' - ct > mx) {

                mx = s[j] - '0' - ct;

                ind = j;

            }

            if(s[j] - '0' - ct == mx) {

                ind = min(ind, j);

            }

            ct++;

        }

        cout << mx;

        for(int j = ind; j > i; j--) {

            swap(s[j],s[j - 1]);

        }

    }

    cout << endl;

    

}







int main() {

    int t;

    cin >> t;

    while(t--) {

        solution();

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



void solve(){

    string s;

    cin >> s;

    int n = s.size();

    string ans = "";

    vector<int> last;

    for(int i = 0; i < min(10, n); ++i)

        last.push_back(s[i]-'0');



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

        int greatest = -1;

        int used = 0;

        for(int j = 0; j < last.size(); ++j){

            if(last[j] - j > greatest){

                greatest = last[j] - j;

                used = j;

            }

        }

        ans.push_back(greatest + '0');

        last.erase(last.begin() + used);

        if(i + 10 < n) last.push_back(s[i + 10]-'0');

    }



    cout << ans << "\n";

}



int main(){

    cin.tie(0)->sync_with_stdio(0);

    cin.exceptions(cin.failbit);

    int t = 1;

    cin >> t;

    while(t--) solve();



    return 0;

}

Solution 2 (runtime: 109 ms):
//Lingshaisthebest

#include <bits/stdc++.h>

using namespace std;

#define fi first

#define se second

#define ll long long

#define ps push

const ll N=2e5+5;

const ll mod=1e9+7;

const ll INF=1e18;

#define endl '\n'

#define pb push_back

#define th third

#define fo four

ll n,m,k,i,j,x,y,z,a[N];

int main() {

#ifndef ONLINE_JUDGE

freopen("inp.txt", "r", stdin);

freopen("out.txt", "w", stdout);

#endif

ll t;

cin >> t;

while (t--){

string s;

cin >> s;

n=s.size();

for (i=0;i<s.size();i++) a[i+1]=s[i]-'0';

for (i=1;i<=n;i++){

ll ma=a[i],pos=i;

for (j=i+1;j<=min(n,i+9);j++){

if (a[j]-(j-i)>ma){

pos=j;ma=a[j]-(j-i);

}

}

a[pos]=ma;

while (pos>i){

swap(a[pos],a[pos-1]);

pos--;

}

}

for (i=1;i<=n;i++) cout << a[i];

cout << endl;

}

return 0;

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

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int maxn = 2e5+3;
ll i,j,p,q,n,m,k,t,a[maxn],ans,b[maxn];
void solve()
{
    cin>>n;
    ans = 0;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }
    for(i=n;i>=2;i--){
        ans = max(ans,a[i]-a[1]);
        ans = max(ans,a[1]-a[i]);
        p = a[i] - a[i-1];
        q = a[2] - a[1];
        if(p-q<q-p){
            for(j=1;j<=i;j++)
                b[j] = a[i-j+1];
        }
        else{
            for(j=1;j<=i;j++)
                b[j] = a[j];
        }
        for(j=1;j<i;j++)
            a[j] = b[j+1]-b[j];

    }
    ans = max(ans,a[1]);
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    while(t--)
        solve();
    return 0;
}


Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int32_t main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int t=1;
  cin>>t;
  while(t--)
  {
   ll n;
   cin>>n;
   ll a[n+1];
   for(int i=1;i<=n;i++)
    cin>>a[i];
   ll ans=-1e18;
   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)
      sum=max(sum,-sum);
    ans=max(ans,sum);
    for(int j=1;j<n-i+1;j++)
      a[j]=a[j+1]-a[j];

   }
   cout<<ans<<'\n';
  }
  return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;

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

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

int main()
{
    fastIO();

    int t;
    cin >> t;
   

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


Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
int t;
long long v[1010];
int main()
{
    cin>>t;
    long long ans;
    while(t--) {
        ans=INT_MIN;
        int n;
        cin>>n;
        //vector<int> v(n);
        for(int i=1;i<=n;i++){
            cin>>v[i];
        }
        int now=n;
        for(int i=1;i<=n;i++){
            long long sum=0;
            for(int i=1;i<=now;i++) {
                sum+=v[i];
            }
            if(i==1) ans=max(ans,sum);
            else ans=max(ans,max(sum,-sum));
            for(int i=1;i<now;i++) v[i]=v[i+1]-v[i];
            now--;
        }
        cout<<ans<<endl;
    }
    return 0;
}