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

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<vector>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    vector<string> myvec;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        myvec.push_back(max_str(st));
        num--;
    }
    for(auto str:myvec)
    {
        cout<<str<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<vector>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    vector<string> myvec;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        myvec.push_back(max_str(st));
        num--;
    }
    for(auto str:myvec)
    {
        cout<<str<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update=false;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update=false;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
        }
        update=false;
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update=false;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
            update=false;
        }
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<iostream>
using namespace std;

string max_str(string &s)
{
    string maxstr=s;
    bool update=false;
    int i=1;
    while(true)
    {
        if(i==s.size())
        {
            i=1;
            if(!update)
            {
                return maxstr;
            }
            update=false;
        }
        if(s[i]!='0')
        {
            char temp=s[i-1];
            int num=s[i]-'0';
            num=num-1;
            s[i-1]=num+'0';
            s[i]=temp;
        }
        if(maxstr<s)
        {
            maxstr=s;
            update=true;
        }
        else 
        {
            s=maxstr;
        }
        i++;
    }
}
int main()
{
    string st;
    int num;
    cin>>num;
    while(num>0)
    {
        cin>>st;
        cout<<max_str(st)<<endl;
        num--;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<iostream>
using namespace std;

int main()
{
    string s;
    int num;
    cin>>num;
    while(num--)
    {
        cin>>s;
        int swapped;
        do {
            swapped = 0;
            for (int i = 1; i < s.size(); i++) {
                if (s[i] > s[i - 1] + 1) {
                   
                    char temp = s[i - 1];
                    s[i - 1] = s[i] - 1;
                    s[i] = temp;
                    swapped = 1; 
                }
            }
        } while (swapped); 
        cout<<s<<endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void sol() {
    int n, m; cin >> n >> m;
    map<int, int>a, b;
    vector<int> A;
    for(int i = 1; i <= n; ++i) {
        int x; cin >> x;
        if(!a[x]) A.push_back(x);
        a[x]++;
    }
    for(int i = 1; i <= m; ++i) {
        int x; cin >> x;
        b[x]++;
    }
    sort(A.begin(), A.end());
    for(auto x : A) {
        int mn = min(a[x], b[x]);
        a[x] -= mn; b[x] -= mn;
        if(a[x + 1]) {
            mn = min({a[x], a[x + 1], b[2 * x + 1]});
            a[x] -= mn; a[x + 1] -= mn; b[2 * x + 1] -= mn;
        } else {
            if(x == 1) continue;
            mn = min({a[1] / x, a[x], b[2 * x]});
            a[1] -= (x * mn); a[x] -= mn; b[2 * x] -= mn;
            mn = min({a[1] / (x - 1), a[x], b[2 * x - 1]});
            a[1] -= ((x - 1) * mn); a[x] -= mn; b[2 * x - 1] -= mn;
            a[2 * x] += a[x] / 2;
            a[x] %= 2;
            mn = min(a[2 * x], b[2 * x]);
            a[2 * x] -= mn; b[2 * x] -= mn;
            mn = min({a[1] / x, a[x], b[2 * x]});
            a[1] -= (x * mn); a[x] -= mn; b[2 * x] -= mn;
            mn = min({a[1] / (x - 1), a[x], b[2 * x - 1]});
            a[1] -= ((x - 1) * mn); a[x] -= mn; b[2 * x - 1] -= mn;
        }
    }
    int d = 0;
    for(auto [x, cnt] : a) {
        if(x == 1) continue;
        d += (cnt > 0);
    }
    if(d) return void(cout << "NO\n");
    for(auto[x, cnt] : b) {
        if(a[1] < (cnt * x)) return void(cout << "NO\n");
        else a[1] -= (cnt * x);
    }
    if(a[1]) cout << "NO\n";
    else cout << "YES\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int T = 1; cin >> T;
    while (T--) sol();
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

# define endl '\n'
# define ll long long
# define vi vector<int>
# define vl vector<ll>
# define vc vector<char>
# define mii map<int,int>
# define mll map<ll,ll>
ll MOD = 1e9 + 7;
ll MOD2 = 998244353;


void solve();

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
    return 0;
}

void solve(){
    ll n,temp;
    cin>>n;
    vl arr;
    for(int i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    ll flag=0;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(arr[i]>arr[i+1]){
                flag=1;
                break;
            }
        }
        else{
            if(arr[i]>arr[i+1]){
                if(arr[i]-arr[i-1]>arr[i+1]){
                    flag=1;
                    break;
                }
                else{
                    arr[i]-=arr[i-1];
                    arr[i-1]=0;
                }
            }
        }
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    
    
}
    




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

# define endl '\n'
# define ll long long
# define vi vector<int>
# define vl vector<ll>
# define vc vector<char>
# define mii map<int,int>
# define mll map<ll,ll>
ll MOD = 1e9 + 7;
ll MOD2 = 998244353;


void solve();

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
    return 0;
}

void solve(){
    ll n,temp;
    cin>>n;
    vl arr;
    for(int i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    ll flag=0;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(arr[i]>arr[i+1]){
                flag=1;
                break;
            }
        }
        else{
                if(arr[i]-arr[i-1]>arr[i+1]){
                    flag=1;
                    break;
                }
                else{
                    arr[i]-=arr[i-1];
                    arr[i-1]=0;
                }
        }
    }
    for(int i=0;i<n-1;i++){
        if(arr[i]>arr[i+1]){
            flag=1;
            break;
        }
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    
    
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

# define endl '\n'
# define ll long long
# define vi vector<int>
# define vl vector<ll>
# define vc vector<char>
# define mii map<int,int>
# define mll map<ll,ll>
ll MOD = 1e9 + 7;
ll MOD2 = 998244353;


void solve();

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
    return 0;
}

void solve(){
    ll n,temp;
    cin>>n;
    vl arr;
    for(int i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    ll flag=0;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(arr[i]>arr[i+1]){
                flag=1;
                break;
            }
        }
        else{
            if(arr[i]>arr[i+1]){
                if(arr[i]-arr[i-1]>arr[i+1]){
                    flag=1;
                    break;
                }
                else{
                        arr[i-1]-=arr[i];
                        arr[i]=0;
                }
            }
        }  
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    
    
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

# define endl '\n'
# define ll long long
# define vi vector<int>
# define vl vector<ll>
# define vc vector<char>
# define mii map<int,int>
# define mll map<ll,ll>
ll MOD = 1e9 + 7;
ll MOD2 = 998244353;


void solve();

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
    return 0;
}

void solve(){
    ll n,temp;
    cin>>n;
    vl arr;
    for(int i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    ll flag=0;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(arr[i]>arr[i+1]){
                flag=1;
                break;
            }
        }
        else{
            if(arr[i]>arr[i+1]){
                if(arr[i]-arr[i-1]>arr[i+1]){
                    flag=1;
                    break;
                }
                else{
                        arr[i-1]-=arr[i];
                        arr[i]=0;
                }
            }
        }  
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    
    
}
    




Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

# define endl '\n'
# define ll long long
# define vi vector<int>
# define vl vector<ll>
# define vc vector<char>
# define mii map<int,int>
# define mll map<ll,ll>
ll MOD = 1e9 + 7;
ll MOD2 = 998244353;


void solve();

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
    return 0;
}

void solve(){
    ll n,temp;
    cin>>n;
    vl arr;
    for(int i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    ll flag=0;
    for(int i=0;i<n-1;i++){
        if(i==0){
            if(arr[i]>arr[i+1]){
                flag=1;
                break;
            }
        }
        else{
            if(arr[i]>arr[i+1]){
                if(arr[i]-arr[i-1]>arr[i+1]){
                    flag=1;
                    break;
                }
                else{
                    arr[i]-=arr[i-1];
                    arr[i-1]=0;
                }
            }
        }
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    
    
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N = 1000 + 10;
const int M = 1e9 + 7;
const int inf = 1e12;

int a[N];

void gg(){
    int n; cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
        a[v[i]] = i + 1;
    }

    vector<int>ord;
    for(int i=1;i<=n;i++) ord.push_back(i);
    vector<pair<int,int>>ans;
    for(int i=n-1;i>=0;i--){
        int x = v[i];
        int pos;
        for(int j=0;j<n;j++){
            if(ord[j] == x){
                pos = j;
            }
        }

        // overtake fronts
        for(int j=0;j<pos;j++){
            ans.push_back({x, ord[j]});
        }
        // reverse overtake.
        vector<int>nord;
        vector<int>vis(n, 0);
        for(int j=0;j<n;j++){
            if(j == pos) continue;
            int y = ord[j];
            int xf = a[x];
            int yf = a[y];

            if(xf > yf){
                ans.push_back({y, x});
                nord.push_back(y);
                vis[j] = 1;
            }
        }
        nord.push_back(x);
        for(int j=0;j<n;j++){
            if(j == pos or vis[j] == 1) continue;
            nord.push_back(ord[j]);
        }

        ord = nord;
    }

    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }
}

/* void solve(){

    int n; cin >> n;
    vector<int>v(n);
    for(int i=1;i<=n;i++){
        cin >> v[i];
        a[v[i]] = i;
    }
    vector<pair<int,int>>ans;
    // for(int i=n;i>=1;i--){
    //     int x = v[i];
    //     for(int y=x-1;y>=1;y--){
    //         ans.push_back({x, y});
    //     }
    // }
    // vector<pair<int,int>>ans;
    for(int i=n;i>=1;i--){
        for(int j=i-1;j>=1;j--){
            ans.push_back({i, j});
        }
        for(int j=i-1;j>=1;j--){
            int x = a[i];
            int y = a[j];

            if(y < x){
                ans.push_back({j, i});
            }
        }
    }

    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }

} */


signed main(){
    Fast_IO()
    int t = 1;
    // cin >> t;
    for(int i=1;i<=t;i++){
        // cout << "Case #" << i << ": ";
        gg();
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <cassert>
using namespace std;
using namespace __gnu_pbds;
#define num1bit(x) __builtin_popcountll(x)
#define ISOK(x,y,z) cout<<(x?(y):(z));
#define OK(x) ISOK(x,"YES\n","NO\n")
#define C continue
#define B break
#define R return
#define nd second
#define st first
#define bn begin()
#define ed end()
#define wte long Tests ; cin >> Tests ; while(Tests--)
#define wtede long Tests ; cin >> Tests ; for(int testcase = 1; testcase <=Tests;testcase++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define b(myint,z,size) bitset<size>z(myint) ; cout<<z<<endl ;
template<typename T>ostream& operator<<(ostream& stream, pair<T, T>& pair){ stream << pair.first << ' ' << pair.second; return stream; };
template<typename T>istream& operator>>(istream& stream, pair<T, T>& pair){ stream >> pair.first >> pair.second; return stream; };
// #define endl '\n'
#define pb push_back
#define SPR(a) cout<<fixed<<setprecision(a) ;
#define sleep(a) this_thread::sleep_for(chrono::milliseconds(a));
#define all(x) (x).begin(), (x).end()	
void dbg_out(){ cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T){ cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqi;
const ll oo = (int)1e9 + 7, mod = oo, moD = 998244353, lloo = 1e18;
const ld eps = 1e-8, PI = 3.14159265359;
inline ll mid(ll l, ll r){ R(r - l) / 2 + l; }
inline ll MSB(int n){ R 63 - __builtin_clzll(n); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename y, typename T> y smax(y& a, const T& b){ if(a < b) a = b; R a; }
template<typename y, typename T> y smin(y& a, const T& b){ if(a > b) a = b; R a; }

ll n, x, y, z, k, m;
ll a[2000];
#define TCASES
// #define DEBUG
void maininit(){}
void solve(){
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		ans += a[i];
	}
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= n - i; j++) a[j] = a[j + 1] - a[j];
		smax(ans, (a[n - i] - a[1]));
		smax(ans, -(a[n - i] - a[1]));
	}
	cout << ans << endl;

}

int main(){
#ifndef DEBUG
	IOS;
#endif
	auto start = chrono::high_resolution_clock::now();
	maininit();
#ifdef TCASES
	wte
#endif
		solve();
#ifdef DEBUG
	auto end = chrono::high_resolution_clock::now();
	cerr << "\nExecution time: "
		<< chrono::duration_cast<chrono::milliseconds>(end - start).count()
		<< " ms" << endl;
#endif
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define nl "\n"
#define sp " "
#define pb push_back
#define fr(a,b,i) for(int i=a; i<b; i++)
#define v(type) vector<type>
#define vv(type) vector<vector<type>>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define rf(b,a,i) for(int i=b; i>=a; i--)
#define w(t) while(t--)
#define mset multiset
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ms multiset
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define si set<int>
#define sll set<ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define msi multiset<int>
#define msl multiset<ll>
using namespace std;

void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template<typename T>
void print(v(T) v) {
    fr(0, v.size(), i) { cout << v[i] << " "; }
    cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
 
 
ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
 
 
void run() {
    int n;
    cin>>n;
    if (n == 1) { 
        int num;
        cin >> num;
        cout << num << nl;  
        return;
    }
    vi a_old(n);
    int sum = 0;
    fr(0, n, i) {
        cin>>a_old[i];
        sum += a_old[i];
    }
    int k = n;
    while(k>1){
    vi a_new(k - 1);
    fr(0,k-1,i){
        a_new[i] = a_old[i+1]-a_old[i];
    }
    a_old = a_new;
    k--;
    }
    cout<<max(sum,abs(a_old[0]))<<nl;
    
;}

int main() {
    fastIO();
 
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
 
 
    int t;
    cin >> t;
    w(t) {
        run();
    }
    return 0;
}