ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2;
vi arrM, arr;

bool invComp(int a, int b){
    return a>=b;
}

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr.resize(n+50, 0);
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        l--; r--;
        ans1=ans2=0;
        arrM=arr;
        sort(arrM.begin(), arrM.begin()+r+1, invComp);
        for(int i=l; i<=r; i++){
            ans1+=arrM[i];
        }
        arrM=arr;
        sort(arrM.begin()+l, arrM.begin()+n);
        for(int i=l; i<=r; i++){
            ans2+=arrM[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}


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

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2, a;
vi arr1, arr2;

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr1.clear();
        arr2.clear();
        l--; r--;
        for(int i=0; i<n; i++){
            cin >> a;
            if(i<=r) arr1.pb(a);
            if(i>=l) arr2.pb(a);
        }
        ans1=ans2=0;
        sort(all(arr1));
        sort(all(arr2));
        for(int i=0; i<=r-l; i++){
            ans1+=arr1[i];
            ans2+=arr2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 6):
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2;
vi arr, a1, a2;

bool invComp(int a, int b){
    return a>=b;
}

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr.resize(n, 0);
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        l--; r--;
        a1=a2=arr;
        sort(a1.begin(), a1.begin()+r+1, invComp);
        sort(a2.begin()+l, a2.end());
        ans1=ans2=0;
        for(int i=l; i<=r; i++){
            ans1+=a1[i];
            ans2+=a2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 6):
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2;
vi arr, a1, a2;

bool invComp(int a, int b){
    return a>=b;
}

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr.resize(n, 0);
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        l--; r--;
        a1=a2=arr;
        sort(a1.begin(), a1.begin()+r+1, invComp);
        sort(a2.begin()+l, a2.end());
        ans1=ans2=0;
        for(int i=l; i<=r; i++){
            ans1+=a1[i];
            ans2+=a2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}


Submission (verdict: Runtime error on test 6):
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2;
vi arr, a1, a2;

bool invComp(int a, int b){
    return a>=b;
}

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr.resize(n, 0);
        a1.resize(n, 0);
        a2.resize(n, 0);
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        l--; r--;
        a1=a2=arr;
        sort(a1.begin(), a1.begin()+r+1, invComp);
        sort(a2.begin()+l, a2.end());
        ans1=ans2=0;
        for(int i=l; i<=r; i++){
            ans1+=a1[i];
            ans2+=a2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

void solve() {
    int l, r;
    cin >> l >> r;
    int a = r & ~(r - l);
    int b = a + 1;
    int c = (a == l ? r : l);
    cout << a << " " << b << " " << c << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

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


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

void solve() {
    ll l, r;
    std::cin >> l >> r;

    ll xor_val = l ^ r;
    ll highest_bit = 0;
    while (xor_val >>= 1) {
        highest_bit++;
    }
   
    ll mask = (1 << highest_bit) - 1;
    ll a = l | mask;
    ll b = a + 1;
    for(ll i=l;i<=r;i++){
        if(i!=a && i!=b){
            cout<<a<<" "<<b<<" "<<i<<endl;
            return;
        }
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t = 1;
    std::cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll l, r;
    cin >> l >> r;
    ll a = 0, b = 0;

    for(ll i = 29; i >= 0; i--){
        ll d = 1 << i;
        for(ll x = l; x <= r; x++){
            if(x % d == 0 && x != 0 && (x-1) >= l && (x-1) <= r){
                a = x;
                b = x - 1;
                break;
            }
        }
        if(a != 0 && b != 0) break; // If `a` and `b` are found, break the loop.
    }

    for(ll i = l; i <= r; i++){
        if(i != a && i != b){
            cout << a << " " << b << " " << i << endl;
            return;
        }
    }
}

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


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

void solve() {
    int l, r;
    cin >> l >> r;
    int a = r & ~(r - l);
    int b = a + 1;
    int c = (a == l ? r : l);
    cout << a << " " << b << " " << c << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
      ll l,r;
	  cin>>l>>r;
	  ll a=0;
	  ll b=0;
	  ll c=0;
	  for(ll i=29;i>=0;i--){
	      ll d=1<<i;
	     for(ll x=r;x>=l;x--){
	          if(x%d == 0 && x!=0 && (x-1)>=l && x-1<=r){
	              a=x;
	              b=x-1;
	              break;
	          }
	     }
	  }
	  for(ll i=l;i<=r;i++){
	      if(i!=a && i!=b){
	          cout<<a<<" "<<b<<" "<<i<<endl;
	          return ;
	      }
	  }
}
int main() {
	// your code goes here
	ll t;
	cin>>t;
	while(t--){
	solve();
	    
	}
	return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
      ll l,r;
	  cin>>l>>r;
	  ll a=0;
	  ll b=0;
	  ll c=0;
	  for(ll i=29;i>=0;i--){
	      ll d=1<<i;
	     for(ll x=r;x>=l;x--){
	          if(x%d == 0 && x!=0 && (x-1)>=l && x-1<=r){
	              a=x;
	              b=x-1;
	              break;
	          }
	     }
	  }
	  for(ll i=l;i<=r;i++){
	      if(i!=a && i!=b){
	          cout<<a<<" "<<b<<" "<<i<<endl;
	          return ;
	      }
	  }
}
int main() {
	// your code goes here
	ll t;
	cin>>t;
	while(t--){
	solve();
	    
	}
	return 0;

}


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll l, r;
    cin >> l >> r;
    ll a = 0, b = 0;

    for(ll i = 29; i >= 0; i--){
        ll d = 1 << i;
        for(ll x = l; x <= r; x++){
            if(x % d == 0 && x != 0 && (x-1) >= l && (x-1) <= r){
                a = x;
                b = x - 1;
                break;
            }
        }
        if(a != 0 && b != 0) break; // If `a` and `b` are found, break the loop.
    }

    for(ll i = l; i <= r; i++){
        if(i != a && i != b){
            cout << a << " " << b << " " << i << endl;
            return;
        }
    }
}

int main() {
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        for(int j=i+1;j<s.size()&&j<=i+9;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        if(max_index!=i)
        { string p=s;
          
          for(int j=i+1;j<=max_index;j++)
          {
            p[j]=s[j-1];
          }
          p[i]=d+'0';
          s=p;
          
        }
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        for(int j=i+1;j<s.size()&&j<=i+9;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        if(max_index!=i)
        { string p=s;
          
          for(int j=i+1;j<=max_index;j++)
          {
            p[j]=s[j-1];
          }
          p[i]=d+'0';
          s=p;
          
        }
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        int e=s.size();
        int q=min(e,i+10);
        for(int j=i+1;j<q;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        if(max_index!=i)
        { string p=s;
          
          for(int j=i+1;j<=max_index;j++)
          {
            p[j]=s[j-1];
          }
          p[i]=d+'0';
          s=p;
          
        }
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        int e=s.size();
        int q=min(e,i+10);
        for(int j=i+1;j<q;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        if(max_index!=i)
        { string p=s;
          
          for(int j=i+1;j<=max_index;j++)
          {
            p[j]=s[j-1];
          }
          p[i]=d+'0';
          s=p;
          
        }
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}

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

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        int e=s.size();
        int q=min(e,i+10);
        for(int j=i+1;j<q;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        
        while(max_index>i)
        {
          swap(s[max_index],s[max_index-1]);
          max_index--;
        }
        s[i]=d+'0';
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<int>>> dp;
int maxm(int a, int b, int c) {
    int maxm = max(a,b);
    maxm = max(maxm,c);
    return maxm;
}
int recur(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if (i < a.length() && a[i] == c[k]) {
        return recur(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return recur(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return 1+min(recur(a,b,c,i+1,j,k+1), recur(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return min(recur(a,b,c,i+1,j,k), 1+recur(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return min(recur(a,b,c,i,j+1,k), 1+recur(a,b,c,i,j,k+1));
    } else return 0;
}

int mem(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if(dp[i][j][k] != -1) return dp[i][j][k];
    if (i < a.length() && a[i] == c[k]) {
       return dp[i][j][k] = mem(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return dp[i][j][k] = mem(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return dp[i][j][k] = 1+min(mem(a,b,c,i+1,j,k+1), mem(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i+1,j,k),1+mem(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i,j+1,k), 1+mem(a,b,c,i,j,k+1));
    } else return dp[i][j][k] = 0;
}

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
       dp.resize(a.length(), vector<vector<int>> (b.length(), vector<int>(c.length(), -1)));
        cout<<mem(a,b,c,0,0,0)<<endl;
        //cout<<recur(a, b, c, 0, 0, 0)<<endl;
    }
}
/*
   i
egg
 j
annie
    k
egaegaeg
   1
  i
ab
 j
ba
    k
aabb
   
1
0
2
0
3
2
3

*/
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)




void solve(){
    ll n;
    cin >> n;
    vector<ll>arr(n);
    for(auto &i : arr)cin >> i;

    ll max_sum = 0;

    for(ll i = 0 ; i < n ; i++)max_sum += arr[i];

    vector<ll>diff;
    for(ll i = 0 ; i < n - 1 ; i++)diff.push_back(arr[i + 1] - arr[i]);
    if(diff.size() == 1){
        max_sum = max(max_sum , max(diff[0] , -diff[0]));
        cout<<max_sum<<"\n";
        return;
    }

    for(ll i = 1 ;  i < n ; i++){
         if(diff.size() == 1){
            max_sum = max(max_sum , max(diff[0] , -diff[0]));
            break;
         }
         vector<ll>diff2;
         for(ll j = 0 ; j < diff.size() - 1 ; j++){
             diff2.push_back(diff[j + 1] - diff[j]);
         }
    
         ll p1 = diff[diff.size() - 1] - diff[0];
         ll p2 = -p1;
         max_sum = max(max_sum , max(p1 , p2));
         diff = diff2;
    }
    cout<<max_sum<<"\n";
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

   fio;
   int testcase =  1;
   cin >> testcase;
   while(testcase--){
     solve();
   }

 return 0;   
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)




void solve(){
    ll n;
    cin >> n;
    vector<ll>arr(n);
    for(auto &i : arr)cin >> i;

    ll max_sum = 0;

    for(ll i = 0 ; i < n ; i++)max_sum += arr[i];

    vector<ll>diff;
    for(ll i = 0 ; i < n - 1 ; i++)diff.push_back(arr[i + 1] - arr[i]);
    ll sum = accumulate(diff.begin() , diff.end() , (ll)0);
    max_sum = max(max_sum , max(sum  , -1 * sum));
    if(diff.size() == 1){
        max_sum = max(max_sum , max(diff[0] , -diff[0]));
        cout<<max_sum<<"\n";
        return;
    }

    for(ll i = 1 ;  i < n ; i++){
         if(diff.size() == 1){
            max_sum = max(max_sum , max(diff[0] , -1 * diff[0]));
            break;
         }
         vector<ll>diff2;
         for(ll j = 0 ; j < diff.size() - 1 ; j++){
             diff2.push_back(diff[j + 1] - diff[j]);
         }
    
         ll p1 = diff[diff.size() - 1] - diff[0];
         ll p2 = -p1;
         max_sum = max(max_sum , max(p1 , p2));
         diff = diff2;
    }
    cout<<max_sum<<"\n";
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

   fio;
   int testcase =  1;
   cin >> testcase;
   while(testcase--){
     solve();
   }

 return 0;   
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)




void solve(){
    ll n;
    cin >> n;
    vector<ll>arr(n);
    for(auto &i : arr)cin >> i;

    ll max_sum = 0;

    for(ll i = 0 ; i < n ; i++)max_sum += arr[i];

    vector<ll>diff;
    for(ll i = 0 ; i < n - 1 ; i++)diff.push_back(arr[i + 1] - arr[i]);
    if(diff.size() == 1){
        max_sum = max(max_sum , max(diff[0] , -diff[0]));
        cout<<max_sum<<"\n";
        return;
    }

    for(ll i = 1 ;  i < n ; i++){
         vector<ll>diff2;
         for(ll j = 0 ; j < diff.size() - 1 ; j++){
             diff2.push_back(diff[j + 1] - diff[j]);
         }
         ll p1 = diff[diff.size() - 1] - diff[0];
         ll p2 = -p1;
         max_sum = max(max_sum , max(p1 , p2));
         diff = diff2;
    }
    cout<<max_sum<<"\n";
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

   fio;
   int testcase =  1;
   cin >> testcase;
   while(testcase--){
     solve();
   }

 return 0;   
}


Submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)




void solve(){
    ll n;
    cin >> n;
    vector<ll>arr(n);
    for(auto &i : arr)cin >> i;

    ll max_sum = 0;

    for(ll i = 0 ; i < n ; i++)max_sum += arr[i];

    vector<ll>diff;
    for(ll i = 0 ; i < n - 1 ; i++)diff.push_back(arr[i + 1] - arr[i]);
    if(diff.size() == 1){
        max_sum = max(max_sum , max(diff[0] , -diff[0]));
        cout<<max_sum<<"\n";
        return;
    }

    for(ll i = 1 ;  i < n ; i++){
         if(diff.size() == 1){
            max_sum = max(max_sum , max(diff[0] , -diff[0]));
            break;
         }
         vector<ll>diff2;
         for(ll j = 0 ; j < diff.size() - 1 ; j++){
             diff2.push_back(diff[j + 1] - diff[j]);
         }
    
         ll p1 = diff[diff.size() - 1] - diff[0];
         ll p2 = -p1;
         max_sum = max(max_sum , max(p1 , p2));
         diff = diff2;
    }
    cout<<max_sum<<"\n";
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

   fio;
   int testcase =  1;
   cin >> testcase;
   while(testcase--){
     solve();
   }

 return 0;   
}