ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

using ll = long long;

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

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

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

        ll l = 0;
        while(l<n-1){
            while(min(a[l], a[l+1]) == 0) l++;
            if(l>=n) break;
            ll mini = min(a[l], a[l+1]);
            a[l] -= mini, a[l+1] -= mini;
            l++;
        }

        bool possible = true;
        for(ll i=0; i<n; i++){
            if(a[i]!=0){
                if(i!=n-1){
                    possible = false;
                    break;
                }
            }
        }

        if(possible) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

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

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        if(l==0 || r==n-1){
            cout << sum << endl;
            continue;
        }
        //if not
        //l != 0 && r != n-1
        ll sum1 = 0, sum2 = 0;
        multiset<ll> st1, st2;
        for(ll i=0; i<r; i++){
             st1.insert(a[i]);
        }
        for(ll i=l; i<n; i++){
             st2.insert(a[i]);
        }
        auto it1 = st1.begin(), it2 = st2.begin();
        ll size1 = r-l+1, size2 = r-l+1;
        while(size1!=0 && it1!=st1.end()){
            sum1 += *it1;
            it1++;
            size1--;
        }
        while(size2!=0 && it2!=st2.end()){
            sum2 += *it2;
            it2++;
            size2--;
        }
        ll ans = min(sum1, sum2);
        cout << ans << endl;
        
    }
}
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;

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

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

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        if(l==0 || r==n-1){
            cout << sum << endl;
            continue;
        }
        //if not
        //l != 0 && r != n-1
        ll sum1 = 0, sum2 = 0;
        multiset<ll> st1, st2;
        for(ll i=0; i<r; i++){
             st1.insert(a[i]);
        }
        for(ll i=l; i<n; i++){
             st2.insert(a[i]);
        }
        auto it1 = st1.begin(), it2 = st2.begin();
        ll size1 = r-l+1, size2 = r-l+1;
        while(size1!=0 && it1!=st1.end()){
            sum1 += *it1;
            it1++;
            size1--;
        }
        while(size2!=0 && it2!=st2.end()){
            sum2 += *it2;
            it2++;
            size2--;
        }
        ll ans = min(sum1, sum2);
        cout << ans << endl;
        
    }
}

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

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

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

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        cout << sum << endl;
    }
}
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;

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

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

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        cout << sum << endl;
    }
}

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

using ll = long long;

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

    while(t--){
        ll n, l, r;
        cin >> n >> l >> r;     
        l--, r--;

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

        vector<ll> b = a;
        sort(b.begin(), b.end());
        ll sum = 0;
        map<ll,ll> mp;
        for(ll i=0; i<(r-l+1); i++){
            sum += (b[i]);
            mp[b[i]]++;
        }

        if(l==0 || r==n-1){
            cout << sum << endl;
            continue;
        }
        //if not
        //l != 0 && r != n-1
        ll sum1 = 0, sum2 = 0;
        multiset<ll> st1, st2;
        for(ll i=0; i<=r; i++){
             st1.insert(a[i]);
        }
        for(ll i=l; i<n; i++){
             st2.insert(a[i]);
        }
        auto it1 = st1.begin(), it2 = st2.begin();
        ll size1 = r-l+1, size2 = r-l+1;
        while(size1!=0 && it1!=st1.end()){
            sum1 += *it1;
            it1++;
            size1--;
        }
        while(size2!=0 && it2!=st2.end()){
            sum2 += *it2;
            it2++;
            size2--;
        }
        ll ans = min(sum1, sum2);
        cout << ans << endl;
        
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <numeric>
#include <cstring>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <climits>
#include <random>

using namespace std;

const long long int inf = LLONG_MAX-10000000000ll;
const long long mod = 1e9+7;
const long long mod2 = 998244353;

#define inp(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define inp1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define inp2(a,b,n) for(int i=0;i<n;i++){cin>>a[i]>>b[i];}
#define out(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define out1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<" ";}
#define loop(n) for(int i=0;i<n;i++)
#define loop1(n) for(int i=1;i<=n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define loop2(n) for(int j=0;j<n;j++)
#define neg(n) if(i==n)continue;
#define nl cout<<endl;
#define all(v) v.begin(),v.end()
#define pb push_back
#define ll long long
#define F first
#define S second

typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vpi;
typedef pair<ll,ll> pi;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin>>t;
    while(t--){
        
        int n;
        cin>>n;

        vi v(n+1);
        inp(v,n);
        map<int,int>mp;
        loop(n){
            mp[v[i]] = i;
        }

        vpi ans;
        for(int i=n;i>=1;i--){
            for(int j=0;j<=mp[i];j++){
                if(v[j] > i)ans.pb({v[j],i});
            }
        }

        int st = 0,en = 0;
        while(en<n){
            while(v[en+1] == v[en]+1 && en<n)en++;
            for(int i=st;i<=en;i++){
                for(int j=i+1;j<=en;j++){
                    ans.pb({v[i],v[j]});
                }
            }
            for(int i=en;i>=st;i--){
                for(int j=i-1;j>=st;j--){
                    ans.pb({v[i],v[j]});
                }
            }
            en++;
            st=en;
        }

        cout<<ans.size()<<endl;
        for(auto x : ans){
            cout<<x.F<<" "<<x.S<<endl;
        }

    }
    return 0;
}


/*

cd /Users/prajit/code/Demo/
rm -f demo
g++ -std=c++17 -o demo demo.cpp
./demo < input.txt > output.txt

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

Previous submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum < k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}

Submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = 0, step = vec.size(), index = 0;
        while (sum < k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}

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

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum < k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = 0, step = vec.size(), index = 0;
        while (sum < k)
        {
            step--;
            sum += vec[index++].second;
        }
        step = max(step, 1);
        cout << step << endl;
    }
}
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;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}

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

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans += a[i];
    }
//    int sum = dfs(a, n,  0);
//    cout<<sum<<endl;
    int len = n;
    for(int i=0;i<n;i++)
    {
        int sum = 0;
        for(int j=0;j<len;j++)
        {
            sum+=a[j];
        }
        if(i == 0)
        {
            ans = max(ans, sum);
        }
        else
        {
            ans = max({ans, -sum, sum});
        }

        len--;
        for(int j=0;j<len;j++)
            a[j] = a[j+1] - a[j];
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans += a[i];
    }
//    int sum = dfs(a, n,  0);
//    cout<<sum<<endl;
    int len = n;
    for(int i=0;i<n;i++)
    {
        ll sum = 0;
        for(int j=0;j<len;j++)
        {
            sum+=a[j];
        }
        if(i == 0)
        {
            ans = max(ans, sum);
        }
        else
        {
            ans = max({ans, -sum, sum});
        }

        len--;
        for(int j=0;j<len;j++)
            a[j] = a[j+1] - a[j];
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans += a[i];
    }
//    int sum = dfs(a, n,  0);
//    cout<<sum<<endl;
    int len = n;
    for(int i=0;i<n;i++)
    {
        ll sum = 0;
        for(int j=0;j<len;j++)
        {
            sum+=a[j];
        }
        if(i == 0)
        {
            ans = max(ans, sum);
        }
        else
        {
            ans = max({ans, -sum, sum});
        }

        len--;
        for(int j=0;j<len;j++)
            a[j] = a[j+1] - a[j];
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<ll>a(n);
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans += a[i];
    }
//    int sum = dfs(a, n,  0);
//    cout<<sum<<endl;
    int len = n;
    for(int i=0;i<n;i++)
    {
        ll sum = 0;
        for(int j=0;j<len;j++)
        {
            sum+=a[j];
        }
        if(i == 0)
        {
            ans = max(ans, sum);
        }
        else
        {
            ans = max({ans, -sum, sum});
        }

        len--;
        for(int j=0;j<len;j++)
            a[j] = a[j+1] - a[j];
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int sum = dfs(a, n,  0);
    cout<<sum<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int sum = dfs(a, n,  0);
    cout<<sum<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dfs(vector<int>a, int n, int flag)
{
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }

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

    if(flag == 0)
    {
        //可以翻转
        for(int i=0;i<n/2;i++)
        {
            int tmp = a[i];
            a[i] = a[n - i - 1];
            a[n - i - 1] = tmp;
        }
        sum = max(sum, dfs(a,n, 1));
    }
    for(int i=0;i<n-1;i++)
    {
        a[i] = a[i+1] - a[i];
    }
    sum = max(sum, dfs(a, n-1, 0));
    return sum;
}
void cal()
{
    int n;
    cin>>n;
    vector<int>a(n);
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans += a[i];
    }
//    int sum = dfs(a, n,  0);
//    cout<<sum<<endl;
    int len = n;
    for(int i=0;i<n;i++)
    {
        int sum = 0;
        for(int j=0;j<len;j++)
        {
            sum+=a[j];
        }
        if(i == 0)
        {
            ans = max(ans, sum);
        }
        else
        {
            ans = max({ans, -sum, sum});
        }

        len--;
        for(int j=0;j<len;j++)
            a[j] = a[j+1] - a[j];
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cal();
    }
    return 0;
}