ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s){
    int n=s.length();
    for(int i=n-1; i>0; i--){
        if((s[i-1]-'0')<(s[i]-'0')-1){
            int d=s[i]-'0';
            //cout << d << endl;
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0; i<10; i++){
        operation(s);
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s){
    int n=s.length();
    for(int i=1; i<n; i++){
        if((s[i-1]-'0')<(s[i]-'0')-1){
            int d=s[i]-'0';
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0; i<10; i++){
        operation(s);
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s, int d){
    int n=s.length();
    for(int i=1; i<n; i++){
        if(s[i]==('0'+d) && int(s[i-1]-'0')<d-1){
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=9; i>0; i--){
        for(int j=i; j<10; j++){
            operation(s,j);
        }
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s, int d){
    int n=s.length();
    for(int i=1; i<n; i++){
        if(s[i]==('0'+d) && int(s[i-1]-'0')<d-1){
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=9; i>0; i--){
        for(int j=i; j<10; j++){
            operation(s,j);
        }
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s){
    int n=s.length();
    for(int i=n-1; i>0; i--){
        if((s[i-1]-'0')<(s[i]-'0')-1){
            int d=s[i]-'0';
            //cout << d << endl;
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0; i<10; i++){
        operation(s);
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r; cin>>n>>l>>r;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> left; vector<int> right; vector<int> v;

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

        left.push_back(arr[i]);

    }

    for(int i=l-1;i<r;i++) {

        v.push_back(arr[i]);

    }

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

        right.push_back(arr[i]);

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());

    sort(v.begin(),v.end(),[](const int a,const int b) {

        return a > b;

    });

    int i; int j;

    long long sum = accumulate(v.begin(),v.end(),0);

    long long leftSum = sum; long long rightSum = sum;

    i=0; j=0;

    while(i<=(r-l) && j<(l-1)) {

        if(left[j]>=v[i]) break;

        leftSum -= v[i];

        leftSum += left[j];

        i++; j++;

    }

    i=0; j=0;

    while(i<=(r-l) && j<(n-r)) {

        if(right[j]>=v[i]) break;

        rightSum -= v[i];

        rightSum += right[j];

        i++; j++;

    }

    cout<<min(leftSum,rightSum)<<"\n";

}



int main() {

	int t; cin>>t;

	while(t--) {

	    solve();

	}

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r; cin>>n>>l>>r;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> left; vector<int> right; vector<int> v;

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

        left.push_back(arr[i]);

    }

    for(int i=l-1;i<r;i++) {

        v.push_back(arr[i]);

    }

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

        right.push_back(arr[i]);

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());

    sort(v.begin(),v.end(),[](const int a,const int b) {

        return a > b;

    });

    int i; int j;

    long long sum = accumulate(v.begin(),v.end(),0);

    long long leftSum = sum; long long rightSum = sum;

    i=0; j=0;

    while(i<=(r-l) && j<(l-1)) {

        if(left[j]>=v[i]) break;

        leftSum -= v[i];

        leftSum += left[j];

        i++; j++;

    }

    i=0; j=0;

    while(i<=(r-l) && j<(n-r)) {

        if(right[j]>=v[i]) break;

        rightSum -= v[i];

        rightSum += right[j];

        i++; j++;

    }

    cout<<min(leftSum,rightSum)<<"\n";

}



int main() {

	int t; cin>>t;

	while(t--) {

	    solve();

	}

}



Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r; cin>>n>>l>>r;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> left; vector<int> right; vector<int> v;

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

        left.push_back(arr[i]);

    }

    for(int i=l-1;i<r;i++) {

        v.push_back(arr[i]);

    }

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

        right.push_back(arr[i]);

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());

    sort(v.begin(),v.end(),[](const int a,const int b) {

        return a > b;

    });

    int i; int j;

    long long sum = accumulate(v.begin(),v.end(),0);

    long long leftSum = sum; long long rightSum = sum;

    i=0; j=0;

    while(i<v.size() && j<left.size()) {

        if(left[j]>=v[i]) break;

        leftSum -= v[i];

        leftSum += left[j];

        i++; j++;

    }

    i=0; j=0;

    while(i<v.size() && j<right.size()) {

        if(right[j]>=v[i]) break;

        rightSum -= v[i];

        rightSum += right[j];

        i++; j++;

    }

    cout<<min(leftSum,rightSum)<<"\n";

}



int main() {

	int t; cin>>t;

	while(t--) {

	    solve();

	}

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r; cin>>n>>l>>r;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> left; vector<int> right; vector<int> v;

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

        left.push_back(arr[i]);

    }

    for(int i=l-1;i<r;i++) {

        v.push_back(arr[i]);

    }

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

        right.push_back(arr[i]);

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());

    sort(v.begin(),v.end(),[](const int a,const int b) {

        return a > b;

    });

    int i; int j;

    long long sum = accumulate(v.begin(),v.end(),0);

    long long leftSum = sum; long long rightSum = sum;

    i=0; j=0;

    while(i<v.size() && j<left.size()) {

        if(left[j]>=v[i]) break;

        leftSum -= v[i];

        leftSum += left[j];

        i++; j++;

    }

    i=0; j=0;

    while(i<v.size() && j<right.size()) {

        if(right[j]>=v[i]) break;

        rightSum -= v[i];

        rightSum += right[j];

        i++; j++;

    }

    cout<<min(leftSum,rightSum)<<"\n";

}



int main() {

	int t; cin>>t;

	while(t--) {

	    solve();

	}

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int n,l,r; cin>>n>>l>>r;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> left; vector<int> right; vector<int> v;

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

        left.push_back(arr[i]);

    }

    for(int i=l-1;i<r;i++) {

        v.push_back(arr[i]);

    }

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

        right.push_back(arr[i]);

    }

    sort(left.begin(),left.end());

    sort(right.begin(),right.end());

    sort(v.begin(),v.end(),[](const int a,const int b) {

        return a > b;

    });

    int i; int j;

    long long sum = accumulate(v.begin(),v.end(),0LL);

    long long leftSum = sum; long long rightSum = sum;

    i=0; j=0;

    while(i<v.size() && j<left.size()) {

        if(left[j]>=v[i]) break;

        leftSum -= v[i];

        leftSum += left[j];

        i++; j++;

    }

    i=0; j=0;

    while(i<v.size() && j<right.size()) {

        if(right[j]>=v[i]) break;

        rightSum -= v[i];

        rightSum += right[j];

        i++; j++;

    }

    cout<<min(leftSum,rightSum)<<"\n";

}



int main() {

	int t; cin>>t;

	while(t--) {

	    solve();

	}

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second
#define eb emplace
#define pb push_back
#define endl '\n'
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mod (int)998244353
#define p(v) for(auto x: v) cout << x << " "; cout << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define input(a,n); for(int i = 0;i<n;i++) cin>>a[i];


int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i <= sqrt(n); i += 6) {
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }
    return true;
}

vector<int> findDivisors(int n) {
    vector<int> divisors;
    for (int i = 1; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            divisors.push_back(i);
            if (i != n / i) divisors.push_back(n / i);
        }
    }
    return divisors;
}

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


void Solve() {
   int n;
   cin >> n;
   vector<int> v;
   int sum=0;
   for(int i=0;i<n;i++){
      int x;
      cin>>x;
      v.push_back(x);
      sum+=x;
   }

   while(n > 1) {
      int sumx = 0, sumy = 0;
      for(int i = 0; i < n; i++) {
         if(i % 2 == 0) {
            sumx += v[i];
            sumy -= v[i];
         } else { 
            sumx -= v[i];
            sumy += v[i];
         }
      }
      
      vector<int> v2(n - 1);
      if(sumy > sumx) {
        for(int i = 0; i < n - 1; i++) {
            v2[i] = v[i + 1] - v[i];
        }
      } else {
        for(int i = 0; i < n - 1; i++) {
           v2[i] = v[n - 2 - i] - v[n - 1 - i]; 
        }
      }
      v = v2;
      n--;
      sum=max(sum,max(sumy,sumx));
   }
   cout << sum << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
         Solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int n = s.length();



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

            int max_val = -1, swap_ind = -1;



            // Start from i+1 to avoid unnecessary checks

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

                int curr_val = (s[j] - '0') - (j - i);

                if (curr_val > max(max_val,s[i]-'0')) {

                    max_val = curr_val;

                    swap_ind = j;

                }

            }



            // If a valid swap index is found, swap the characters

            if (swap_ind != -1) {

                

                for(int k=swap_ind;k>i;k--){

                    s[k]=s[k-1];

                }

                s[i]=max_val+'0';

            }

            

        }

        cout << s << endl;

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int n = s.length();



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

            int max_val = s[i]-'0', swap_ind=i;

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

                int curr_val = (s[j] - '0') - (j - i);

                if (curr_val > max_val) {

                    max_val = curr_val;

                    swap_ind = j;

                }

            }

            for(int k=swap_ind;k>i;k--){

                s[k]=s[k-1];

            }

            s[i]=max_val+'0';

        }

        cout << s << endl;

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int n = s.length();



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

            int max_val = s[i]-'0', swap_ind=i;

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

                int curr_val = (s[j] - '0') - (j - i);

                if (curr_val > max_val) {

                    max_val = curr_val;

                    swap_ind = j;

                }

            }

            for(int k=swap_ind;k>i;k--){

                s[k]=s[k-1];

            }

            s[i]=max_val+'0';

        }

        cout << s << endl;

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int n = s.length();



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

            int max_val = -1, swap_ind = -1;



            // Start from i+1 to avoid unnecessary checks

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

                int curr_val = (s[j] - '0') - (j - i);

                if (curr_val > max(max_val,s[i]-'0')) {

                    max_val = curr_val;

                    swap_ind = j;

                }

            }



            // If a valid swap index is found, swap the characters

            if (swap_ind != -1) {

                

                for(int k=swap_ind;k>i;k--){

                    s[k]=s[k-1];

                }

                s[i]=max_val+'0';

            }

            

        }

        cout << s << endl;

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}



Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int n = s.length();



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

            int max_val = s[i]-'0', swap_ind=i;

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

                int curr_val = (s[j] - '0') - (j - i);

                if (curr_val > max_val) {

                    max_val = curr_val;

                    swap_ind = j;

                }

            }

            for(int k=swap_ind;k>i;k--){

                s[k]=s[k-1];

            }

            s[i]=max_val+'0';

        }

        cout << s << endl;

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 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];
      }
      int ans=INT_MIN;
      int curr=n;
      for(int i=1;i<=n;i++){
          int 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();
       }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 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();
       }
}

Submission (verdict: Accepted):
#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();
       }
}