ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main(){
    short t; cin>>t; int n,k;

    while(t--){
        cin>>n>>k;

        vector<int> a(n);

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

        sort(a.begin(), a.end());
        int count=0;
        while(!a.empty()){
            for(int i=0;i<k;i++)
            {
                if(a.empty()) break;
                a.pop_back();
            }
            if(!a.empty()) a.erase(remove(a.begin(), a.end(), a.front()), a.end());
            count++;
        }
        
        cout << count << endl;
    }
    return 0;
}

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

using i64 = long long;

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    std::vector<int> cnt = {1};
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cnt.back()++;
        } else {
            cnt.emplace_back(1);
        }
    }
    std::sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            std::cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    std::cout << 1 << "\n";
}

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

    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main(){
    short t; cin>>t; int n,k;

    while(t--){
        cin>>n>>k;

        vector<int> a(n);

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

        sort(a.begin(), a.end());
        int count=0;
        while(!a.empty()){
            for(int i=0;i<k;i++)
            {
                a.insert(a.begin(), a.front());a.pop_back();
            }
            a.erase(remove(a.begin(), a.end(), a.front()), a.end());
            count++;
        }
        
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    short t; cin>>t; int n,k;

    while(t--){
        cin>>n>>k;

        vector<int> a(n);

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

        sort(a.begin(), a.end());
        int count=0;
        while(!a.empty()){
            for(int i=0;i<k;i++)
            {
                if(a.empty()) break;
                a.pop_back();
            }
            if(!a.empty()) a.erase(remove(a.begin(), a.end(), a.front()), a.end());
            count++;
        }
        
        cout << count << endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


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

using namespace std;


struct cmp{

    bool operator()(vector<int> &a,vector<int> &b)
    {
        return a[0] < b[0];
    }

};



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

    vector<int> a(n);
    vector<int> b(m);

    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=0;i<m;i++)
        cin >> b[i];


    priority_queue<vector<int>,vector<vector<int>>,cmp> pq;
    
    unordered_map<int,int> cnta;
    unordered_map<int,int> cntb;

    for(int t:a)
    {
        if(cnta.find(t) == cnta.end())
            cnta[t] = 1;
        

        else
            cnta[t]++;
    }


    for(int t:b)
    {
        if(cntb.find(t) == cntb.end())
            cntb[t] = 1;
        else
            cntb[t]++;
    }

    unordered_map<int,int> gap;
    for(auto &it:cnta)
    {
        if(cntb.find(it.first) == cntb.end())
            gap[it.first] = -it.second;
        else    
            gap[it.first] = cntb[it.first] - it.second;
    }   

    for(auto &it:cntb)
    {
        if(cnta.find(it.first) == cnta.end())
            gap[it.first] = cntb[it.first];
    }


    for(auto &it:gap)
    {
        pq.push({it.first,it.second});
    }



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

        cout << pq.size() << "\n";

        while(!pq.empty() && (pq.top()[1] == 0 || pq.top()[1] != gap[pq.top()[0]]))
        {
            pq.pop();
        }

        

        if(pq.empty())
        {
            cout << "no"  << "\n";
            return;
        }
        
        int num = pq.top()[0];
        int cnt = pq.top()[1];
        cout << num << cnt << "\n";

        if(cnt < 0)
        {
            cout << "no" << "\n";
            return;
        }

        
        pq.pop();
        if(cnt - 1 != 0)
            pq.push({num,cnt-1});
        gap[num] = cnt-1;
        
        if(gap.find(num/2) == gap.end())
            gap[num/2] = 1;
        else
            gap[num/2]++;

        
        if(gap.find((num+1)/2) == gap.end())
            gap[(num+1)/2] = 1;
        else
            gap[(num+1)/2]++;

        
        if(gap[num/2] != 0)
        pq.push({num/2,gap[num/2]});

        
        if(gap[(num+1)/2] != 0)
        pq.push({(num+1)/2,gap[(num+1)/2]});
    }


    while(!pq.empty() && (pq.top()[1] == 0 || pq.top()[1] != gap[pq.top()[0]]))
    {
        pq.pop();
    }



    if(pq.empty())
        cout << "yes" << "\n";
    else
        cout << "no" << "\n";

}



int main()
{
    int t;
    cin >> t;

    while(t--)
        solve();


    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    vector<int> b,c;
    for(int i=0; i<r-1; i++){
        b.push_back(a[i]);
    }
    for(int i=l-1; i<n; i++){
        c.push_back(a[i]);
    }
    s1(b); s1(c);
    
    int num = r-l+1;
    int sum1=0; int sum2=0;
    if(b.size()==0) sum1=INT_MAX;
    if(c.size()==0) sum2=INT_MAX;

    for(int i=0; i<num; i++){
        if(i>=b.size()) {sum1 = INT_MAX; break;}
        else {sum1+=b[i];}
    }
    for(int i=0; i<num; i++){
        if(i>=c.size()) {sum2 = INT_MAX; break;}
        else {sum2+=c[i];}
    }
      cout<<min(sum1,sum2)<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    vector<int> b,c;
    for(int i=0; i<r; i++){
        b.push_back(a[i]);
    }
    for(int i=l-1; i<n; i++){
        c.push_back(a[i]);
    }
    s1(b); s1(c);
    
    int num = r-l+1;
    int sum1=0,sum2=0;

    if(b.size()==0){ sum1=INT_MAX;}
    if(c.size()==0){ sum2=INT_MAX;}

    for(int i=0; i<num; i++){
        if(i>=b.size()) {sum1 = INT_MAX; break;}
        else {sum1+=b[i];}
    }
    for(int i=0; i<num; i++){
        if(i>=c.size()) {sum2 = INT_MAX; break;}
        else {sum2+=c[i];}
    }
      cout<<min(sum1,sum2)<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int num = r-l+1;

    s1(a);
    int sum=0;
    for(int i=0; i<num; i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    vector<int> b,c;
    for(int i=0; i<r-1; i++){
        b.push_back(a[i]);
    }
    for(int i=l-1; i<n; i++){
        c.push_back(a[i]);
    }
    s1(b); s1(c);
    
    int num = r-l+1;
    int sum1=0; int sum2=0;
    if(b.size()==0) sum1=INT_MAX;
    if(c.size()==0) sum2=INT_MAX;

    for(int i=0; i<num; i++){
        if(i>=b.size()) {sum1 = INT_MAX; break;}
        else {sum1+=b[i];}
    }
    for(int i=0; i<num; i++){
        if(i>=c.size()) {sum2 = INT_MAX; break;}
        else {sum2+=c[i];}
    }
      cout<<min(sum1,sum2)<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Problem: 2063B - Subsequence Update
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 ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int num = r-l+1;

    s1(a);
    int sum=0;
    for(int i=0; i<num; i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;

        int a[n];
        ARRIN(n, a);

        int flag = 0;

        f(i, 0, n-1)
        {
            if (a[i] == a[i+1]) continue;

            else if (a[i] > a[i+1])
            {
                flag = 1;
                break;
            }

            else break;
        }

        if (flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
   
    return 0;
}

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        int a[n];
        ARRIN(n, a);

        if (a[0] > a[1])
        {
            cout << "NO" << endl;
        }

        f(i,0,n-1)
        {
            int k = min(a[i], a[i+1]);

            a[i] -= k;
            a[i+1] -= k;
        }

        int flag = 0;

        f(i,0,n-1)
        {
            if (a[i] > a[i+1])
            {
                flag = 1;
                cout << "NO" << endl;
                break;
            }
        }

        if (!flag)
        {
            cout << "YES" << endl;
        }
    }
   
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;

        int a[n];
        ARRIN(n, a);

        int flag = 0;

        f(i, 0, n-1)
        {
            if (a[i] == a[i+1]) continue;

            if (a[i] > a[i+1])
            {
                flag = 1;
                break;
            }
        }

        if (flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
   
    return 0;
}

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;

        int a[n];
        ARRIN(n, a);

        int flag = 0;

        f(i, 0, n-1)
        {
            if (a[i] == a[i+1]) continue;

            else if (a[i] > a[i+1])
            {
                flag = 1;
                break;
            }

            else break;
        }

        if (flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
   
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        int a[n];
        ARRIN(n, a);

        if (a[0] > a[1])
        {
            cout << "NO" << endl;
        }

        f(i,0,n-1)
        {
            int k = min(a[i], a[i+1]);

            a[i] -= k;
            a[i+1] -= k;
        }

        int flag = 0;

        f(i,0,n-1)
        {
            if (a[i] > a[i+1])
            {
                flag = 1;
                cout << "NO" << endl;
                break;
            }
        }

        if (!flag)
        {
            cout << "YES" << endl;
        }
    }
   
    return 0;
}

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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        int a[n];
        ARRIN(n, a);

        if (a[0] > a[1])
        {
            cout << "NO" << endl;
            continue;
        }

        f(i,0,n-1)
        {
            int k = min(a[i], a[i+1]);

            a[i] -= k;
            a[i+1] -= k;
        }

        int flag = 0;

        f(i,0,n-1)
        {
            if (a[i] > a[i+1])
            {
                flag = 1;
                cout << "NO" << endl;
                break;
            }
        }

        if (!flag)
        {
            cout << "YES" << endl;
        }
    }
   
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

#define f(i,l,u)  for (int i = l; i < u; i++)
#define ARRIN(n, A)  for (int i = 0; i < n; i++) {cin >> A[i];}
#define ll long long

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;

        int a[n];
        ARRIN(n, a);

        int flag = 0;

        f(i, 0, n-1)
        {
            if (a[i] == a[i+1]) continue;

            if (a[i] > a[i+1])
            {
                flag = 1;
                break;
            }
        }

        if (flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
   
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 28):
#include "./bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<long long,long long>pll;
typedef vector<pii> vpii;
#define REP(i,x,y) for(int i=x;i<y;i++)
#define F first
#define S second
#define PB push_back
#define PRES(c,x) ((c).find(x)!=(c).end())
#define MOD 1000000007
ll gcder(ll a, ll b) {
   if (b == 0)
   return a;
   return gcder(b, a % b);
}
void file_i_o(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freeopen("input.txt","r",stdin);
    //     freeopen("output.txt","w",stdout);
    // #endif
}
int main(){
    file_i_o();
    ll t;cin >> t;
    while(t--){
        ll n,m;cin >> n >> m;
        multiset<ll>a,b;
        REP(i,0,n){
            ll x;cin >> x;
            a.insert(x);
        }
        REP(i,0,m){
            ll x;cin >> x;
            b.insert(x);
        }
        while(b.size() && a.size() && b.size()<=a.size()){
            //cout<<"In"<<endl;
            auto el=(--b.end());
            auto els=a.lower_bound(*el);
            if(els!=a.end()){
                a.erase(els);
                b.erase(el);
                continue;
            }
            ll mid1=(*(el))/2;
            ll mid2=((*(el))+1)/2;
            b.insert(mid1);
            b.insert(mid2);
            b.erase(el);
        }
        bool ans=(!b.size() && !a.size());
        if(ans){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int Find(vector<int>&k,int cost){
    int sum = 0;
    for (int i = 0; i < k.size(); i++)
    {
        sum+=((cost/k[i])+1);
    }
    return sum;
}
void solve(){

    int n;
    cin>>n;
    vector<int>a;
    for (int i = 0; i < n; i++)
    {
        int temp ;
        cin>>temp;
        a.push_back(temp);
    }
    int ans = accumulate(begin(a),end(a),0);
    while (a.size()>1)
    {
        vector<int>forward;
        vector<int>backward;
        int f = 0;
        int b = 0;
        for (int i = 0; i < a.size()-1; i++)
        {
            b+=a[i]-a[i+1];
            backward.push_back(a[i]-a[i+1]);
        }
        for (int i = 1; i < a.size(); i++)
        {
            f+=a[i]-a[i-1];
            forward.push_back(a[i]-a[i-1]);
        }
        if(f>b){
            a.resize(forward.size());
            a=forward;
        }
        else{
            a.resize(backward.size());
            a=backward;
        }
    }
    ans = max(ans,a[0]);
    cout<<ans<<endl;
    
}

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++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int Find(vector<int>&k,int cost){
    int sum = 0;
    for (int i = 0; i < k.size(); i++)
    {
        sum+=((cost/k[i])+1);
    }
    return sum;
}
void solve(){

    int n;
    cin>>n;
    vector<int>a;
    for (int i = 0; i < n; i++)
    {
        int temp ;
        cin>>temp;
        a.push_back(temp);
    }
    int ans = accumulate(begin(a),end(a),0);
    while (a.size()>1)
    {
        vector<int>forward;
        vector<int>backward;
        int f = 0;
        int b = 0;
        for (int i = 0; i < a.size()-1; i++)
        {
            b+=a[i]-a[i+1];
            backward.push_back(a[i]-a[i+1]);
        }
        for (int i = 1; i < a.size(); i++)
        {
            f+=a[i]-a[i-1];
            forward.push_back(a[i]-a[i-1]);
        }
        if(f>b){
            a.resize(forward.size());
            a=forward;
        }
        else{
            a.resize(backward.size());
            a=backward;
        }
    }
    ans = max(ans,a[0]);
    cout<<ans<<endl;
    
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

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

    return  0;
}

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

    int n;
    cin>>n;
    vector<int>a;
    for (int i = 0; i < n; i++)
    {
        int temp ;
        cin>>temp;
        a.push_back(temp);
    }
    int ans = accumulate(begin(a),end(a),0LL);
    while (a.size()>1)
    {
        vector<int>forward;
        vector<int>backward;
        int f = 0;
        int b = 0;
        for (int i = 0; i < a.size()-1; i++)
        {
            b+=a[i]-a[i+1];
            backward.push_back(a[i]-a[i+1]);
        }
        for (int i = 1; i < a.size(); i++)
        {
            f+=a[i]-a[i-1];
            forward.push_back(a[i]-a[i-1]);
        }
        if(f>b){
            a.resize(forward.size());
            a=forward;
        }
        else{
            a.resize(backward.size());
            a=backward;
        }
    }
    ans = max(ans,a[0]);
    cout<<ans<<endl;
    
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

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

    return  0;
}