ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    int n;

    cin>>n;



    if(n%9==0){

        cout<<"YES"<<endl;

        return;

    }



    int sum=0;

    int cnt3=0,cnt2=0;



    while(n>0){

        int d=n%10;

        sum+=d;

        if(d==2)cnt2++;

        if(d==3)cnt3++;

        n=n/10;

    }



    for(int i=0;i<min(9LL,cnt2+1);i++){

        for(int j=0;j<min(9LL,cnt3+1);j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}



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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    int n;

    cin>>n;



    if(n%9==0){

        cout<<"YES"<<endl;

        return;

    }



    int sum=0;

    int cnt3=0,cnt2=0;



    while(n>0){

        int d=n%10;

        sum+=d;

        if(d==2)cnt2++;

        if(d==3)cnt3++;

        n=n/10;

    }



    for(int i=0;i<min(10LL,cnt2+1);i++){

        for(int j=0;j<min(10LL,cnt3+1);j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    int n;

    cin>>n;



    if(n%9==0){

        cout<<"YES"<<endl;

        return;

    }



    int sum=0;

    int cnt3=0,cnt2=0;



    while(n>0){

        int d=n%10;

        sum+=d;

        if(d==2)cnt2++;

        if(d==3)cnt3++;

        n=n/10;

    }



    for(int i=0;i<min(10LL,cnt2+1);i++){

        for(int j=0;j<min(10LL,cnt3+1);j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}



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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    int n;

    cin>>n;



    int sum=0;

    int cnt3=0,cnt2=0;



    while(n>0){

        int d=n%10;

        sum+=d;

        if(d==2)cnt2++;

        if(d==3)cnt3++;

        n=n/10;

    }



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

        for(int j=0;j<=cnt3;j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    int n;

    cin>>n;



    if(n%9==0){

        cout<<"YES"<<endl;

        return;

    }



    int sum=0;

    int cnt3=0,cnt2=0;



    while(n>0){

        int d=n%10;

        sum+=d;

        if(d==2)cnt2++;

        if(d==3)cnt3++;

        n=n/10;

    }



    for(int i=0;i<min(9LL,cnt2+1);i++){

        for(int j=0;j<min(9LL,cnt3+1);j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mod 1000000007
int n,m,k;
int dp[2010][2010];
int recur(int level,int k){
   if(k==0)return m;

   if(level==n){
      return 0;
   }

   if(dp[level][k]!=-1)return dp[level][k];

   int ans=recur(level+1,k)%mod;
   ans=(ans%mod+(m-recur(level+1,k-1)%mod)%mod);

   return dp[level][k]=ans;
	
}
void solve(){
   int n,k;
   cin>>n>>k;

   vector<int> arr(n);
   unordered_map<int,int> mp;

   for(int i=0;i<n;i++){
      cin>>arr[i];
      mp[arr[i]]++;
   }

   vector<int> b;

   for (auto it = mp.begin(); it != mp.end(); ++it){
      b.push_back(it->second);
   }

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

   for(int i=0;i<b.size()-1;i++){
     if(b[i]>k){
       cout<<b.size()-i<<endl;
return;     }
     k-=b[i];
   }

   cout<<1<<endl;

}

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

    int t;
    cin >> t;
    while (t--) 
    	solve();

    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mod 1000000007

void solve(){
   int n,k;
   cin>>n>>k;

   vector<int> arr(n);
   unordered_map<int,int> mp;

   for(int i=0;i<n;i++){
      cin>>arr[i];
      mp[arr[i]]++;
   }

   vector<int> b;

   for (auto it = mp.begin(); it != mp.end(); ++it){
      b.emplace_back(it->second);
   }

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

   for(int i=0;i<b.size()-1;i++){
     if(b[i]>k){
       cout<<b.size()-i<<endl;
return;     }
     k-=b[i];
   }

   cout<<1<<endl;

}

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

    int t;
    cin >> t;
    while (t--) 
    	solve();

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mod 1000000007

void solve(){
   int n,k;
   cin>>n>>k;

   vector<int> arr(n);
   unordered_map<int,int> mp;

   for(int i=0;i<n;i++){
      cin>>arr[i];
      mp[arr[i]]++;
   }

   vector<int> b;

   for (auto it = mp.begin(); it != mp.end(); ++it){
      b.emplace_back(it->second);
   }

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

   for(int i=0;i<b.size()-1;i++){
     if(b[i]>k){
       cout<<b.size()-i<<endl;
return;     }
     k-=b[i];
   }

   cout<<1<<endl;

}

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

    int t;
    cin >> t;
    while (t--) 
    	solve();

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mod 1000000007

void solve(){
   int n,k;
   cin>>n>>k;

   vector<int> arr(n);


   for(int i=0;i<n;i++){
      int a;
      cin>>arr[i];
   }

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


   vector<int> cnt={1};
   for(int i=1;i<n;i++){
      if(arr[i]==arr[i-1])cnt.back()++;
      else cnt.emplace_back(1);
   }

   

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

   for(int i=0;i<cnt.size()-1;i++){
     if(cnt[i]>k){
       cout<<cnt.size()-i<<endl;
return;     }
     k-=cnt[i];
   }

   cout<<1<<endl;

}

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

    int t;
    cin >> t;
    while (t--) 
    	solve();

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mod 1000000007
int n,m,k;
int dp[2010][2010];
int recur(int level,int k){
   if(k==0)return m;

   if(level==n){
      return 0;
   }

   if(dp[level][k]!=-1)return dp[level][k];

   int ans=recur(level+1,k)%mod;
   ans=(ans%mod+(m-recur(level+1,k-1)%mod)%mod);

   return dp[level][k]=ans;
	
}
void solve(){
   int n,k;
   cin>>n>>k;

   vector<int> arr(n);
   unordered_map<int,int> mp;

   for(int i=0;i<n;i++){
      cin>>arr[i];
      mp[arr[i]]++;
   }

   vector<int> b;

   for (auto it = mp.begin(); it != mp.end(); ++it){
      b.push_back(it->second);
   }

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

   for(int i=0;i<b.size()-1;i++){
     if(b[i]>k){
       cout<<b.size()-i<<endl;
return;     }
     k-=b[i];
   }

   cout<<1<<endl;

}

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

    int t;
    cin >> t;
    while (t--) 
    	solve();

    return 0;
}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

/* clang-format off */

/* TYPES  */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>

/* FUNCTIONS */
#define f(a,n) for(long long int i=a;i<n;i++)
#define cf(i,s,e) for(long long int i=s;i<e;i++)
#define rf(e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()


/* PRINTS */
template <class T>
void print_v(vector<T> &v) { cout << "{"; for (auto x : v) cout << x << ","; cout << "\b}"; }

/* UTILS */
#define M 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }

string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }

string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }

#define yy cout<<"Yes\n"
#define nn cout<<"No\n"

/* -question intuitions:
- dp --compute next result from the previous result of the sequence
        -- you have a choice at each step and each choice can lead to answer

- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n))
or upper/lower bound of something in a sorted sample namespac
 --- where anwer space is sorted and in fixed range

-heap -- find lowest or largest of a segment -- k is given example kth largest or smallest
if k+smallest -- kth smallest--maxheap
if k+largest --kth largest--  minheap
complexity-- nlog(k)
*/


#define inputv(arr,n) {for(int i=0;i<n;i++)cin>>arr[i];}
#define printv(a) {for(auto u:a) cout<<u<<" "; cout<<endl;}
void solve(){
    ll n;
    cin>>n;
    
    string s;
    cin>>s;


    if(n==1){
        yy;
        return;
    }


    
    int i=0;int j = 0 ;
    while(i<n){
        if(i=='.'){
            i++;
            continue;
        }

        if(i==n-1){
            yy;
            return;
        }

        j=i+1;
        while(j<n && s[j]=='.') j++;
        if(j==n) {
            yy;
            return;
        }

        if(s[i]==s[j]){
            i=j;continue;
        }

        if(i==0 || i==n-2){
            if(s[i]!='s'){
                nn;
                return;
            }

        }else{
            nn;
            return;
        }
        i++;
    }
    yy;


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t; cin>>t;
    while(t--){

    solve();
       




    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 7):
t=int(input())
for lll in range(t):
    st=input()
    i=0
    stt=[]
    for ky in st:
        stt.append(int(ky))
    tts=stt[::-1]
    while i!=len(stt)-1:
        if tts[i]>tts[i+1]+1 and i>=0:
            (tts[i+1], tts[i])=(tts[i]-1, tts[i+1])
            i-=1
        else:
            i+=1
    st=tts[::-1]
    ans2=""
    for bb in range(len(stt)):
        ans2+=str(st[bb])
    print(ans2)

Submission (verdict: Time limit exceeded on test 7):
t=int(input())
for lll in range(t):
    st=list(map(int,input().strip()))
    while True:
        i=0
        ans=0
        while i!=len(st)-1:
            if st[i]<st[i+1]-1:
                (st[i], st[i+1])=(st[i+1]-1, st[i])
                ans+=1
            i+=1
        if ans==0:
            break
    all=""
    for pp in st:
        all+=str(pp)
    print(all)
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 5):
def func(st):
    if len(st)==1:
        return st
    lis=[]
    for i in range(len(st)):
        lis.append(int(st[i])-i)
    tt=lis.index(max(lis))
    return str(lis[tt])+func(st[:tt]+st[tt+1:])
    


t=int(input())
for lll in range(t):
    st=input()
    print(func(st))
    






    
    


Submission (verdict: Time limit exceeded on test 7):
t=int(input())
for lll in range(t):
    st=input()
    i=0
    stt=[]
    for ky in st:
        stt.append(int(ky))
    tts=stt[::-1]
    while i!=len(stt)-1:
        if tts[i]>tts[i+1]+1 and i>=0:
            (tts[i+1], tts[i])=(tts[i]-1, tts[i+1])
            i-=1
        else:
            i+=1
    st=tts[::-1]
    ans2=""
    for bb in range(len(stt)):
        ans2+=str(st[bb])
    print(ans2)
Problem: 2050D - Digital string maximization
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 7):
t=int(input())
for lll in range(t):
    st=list(map(int,input().strip()))
    while True:
        i=0
        ans=0
        while i!=len(st)-1:
            if st[i]<st[i+1]-1:
                (st[i], st[i+1])=(st[i+1]-1, st[i])
                ans+=1
            i+=1
        if ans==0:
            break
    all=""
    for pp in st:
        all+=str(pp)
    print(all)

Submission (verdict: Accepted):
import sys
input = sys.stdin.readline
 
t = int(input())
for _ in range(t):
    s = list(input().strip())
    n = len(s)
 
    i = n - 1
    while i > 0:
        while True:
            if s[i] > '0' and ord(s[i]) - ord(s[i - 1]) > 1:
                s[i] = chr(ord(s[i]) - 1)
                s[i], s[i - 1] = s[i - 1], s[i]
                if i < n - 1:
                    i += 1
            else:
                break
        i -= 1
    print(''.join(s))
Problem: 2050D - Digital string maximization
Language: PyPy 3-64


Submission (verdict: Runtime error on test 5):
def func(st):
    if len(st)==1:
        return st
    lis=[]
    for i in range(len(st)):
        lis.append(int(st[i])-i)
    tt=lis.index(max(lis))
    return str(lis[tt])+func(st[:tt]+st[tt+1:])
    


t=int(input())
for lll in range(t):
    st=input()
    print(func(st))
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<ctime>
#include<set>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef long long ll;
const int N = 2e5 + 10;
void solve() {
	int l,r,temp,w = 0,a,b,c;
	cin >> l >> r;
	temp = l ^ r;
	while(temp > 1){
		temp /= 2;
		w++;
	}
	a = (1 << w) - 1;
	b = a + 1;
	c = l;
	while(c == a || c == b) c++;
	cout << a << " " << b << " " << c << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<ctime>
#include<set>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef long long ll;
const int N = 2e5 + 10;
void solve() {
	int l,r,temp,w = 0,a,b,c;
	cin >> l >> r;
	temp = l ^ r;
	while(temp > 1){
		temp /= 2;
		w++;
	}
	a = (1 << w) - 1;
	b = a + 1;
	c = l;
	while(c == a || c == b) c++;
	cout << a << " " << b << " " << c << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#define int long long
#define end "\n"
using namespace std;
const int N = 2e6+10;
int r1[N], l1[N];
int a1[N], b1[N], c1[N];

void slove()
{
	int l, r, cnt = 0, b = 0;
	cin >> l >> r;
	if(r - l == 2)
	{
		cout << r << " " << r - 1 << " " << l << endl;
		return ;
	}
		
 	int a = 0, c = l;
	while(1)
	{
		if(r == 0)
			break;
		cnt ++;
		int t = r % 2;
		r1[cnt] = t;
		t = l % 2;
		l1[cnt] = t;
		r /= 2, l /= 2;
	}
	
	int f = 0;
	for(int i = cnt; i>= 1; i --)
	{

		if(r1[i] != l1[i])
		{
			f = i;
			break;
		}
		a1[i] = r1[i];
		b1[i] = r1[i];
	}
	int x = 1;
	a1[f] = 1;
	b1[f] = 0;
	for(int i = f - 1; i >= 1; i --)
	{
		a1[i] = 0;
		b1[i] = 1;
	}
	
	for(int i = 1; i <= cnt; i ++)
	{
		a += a1[i] * x;
		b += b1[i] * x;
		x *= 2;
		
	}

	cout << a << " " << b << " "  << c << endl;

		
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cout << fixed << setprecision(10);
	
	int T = 1; 
	cin >> T;
	while(T--)
	{
		slove();
	}
}
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;

void solve() {
    int n; cin>> n;
    vector<int> arr(n+1);
    long long int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    int size = n;
    for(int i =1; i< n; i++){
      
      long long int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

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


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

void solve() {
    long long int n; cin>> n;
    vector<long long int> arr(n+1);
    long long int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    long long size = n;
    for(int i =1; i< n; i++){
      
      long long int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        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;

void solve() {
    int n; cin>> n;
    vector<int> arr(n+1);
    int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    int size = n;
    for(int i =1; i< n; i++){
      
      int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
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;

void solve() {
    int n; cin>> n;
    vector<int> arr(n+1);
    int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    int size = n;
    for(int i =1; i< n; i++){
      
      int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

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


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

void solve() {
    int n; cin>> n;
    vector<int> arr(n+1);
    long long int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    int size = n;
    for(int i =1; i< n; i++){
      
      long long int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

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