ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, l,r;
        cin >> n >> l >> r;
        l-=1;
        r-=1;
        int arr[n], arr1[r+1], arr2[n-l];
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            if(i<l)
            arr1[i]=arr[i];
            else if(i>r)
            arr2[i-l]=arr[i];
            else
            {
                arr1[i]=arr[i];
                arr2[i-l]=arr[i];
            }
        }
        sort(arr1, arr1+r+1);
        sort(arr2, arr2+n-l);
        long long int sum1=accumulate(arr1, arr1+r-l+1,0);
        long long int sum2=accumulate(arr2, arr2+r-l+1,0);
        cout << min(sum1, sum2) << endl;
    }
}

Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, l,r;
        cin >> n >> l >> r;
        l-=1;
        r-=1;
        int arr[n];
        vector <int> arr1, arr2;
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            if(i<l)
            arr1.push_back(arr[i]);
            else if(i>r)
            arr2.push_back(arr[i]);
            else
            {
                arr1.push_back(arr[i]);
                arr2.push_back(arr[i]);
            }
        }
        sort(arr1.begin(), arr1.end());
        sort(arr2.begin(), arr2.end());
        long long int sum1=accumulate(arr1.begin(), arr1.begin()+r-l+1,0);
        long long int sum2=accumulate(arr2.begin(), arr2.begin()+r-l+1,0);
        cout << min(sum1, sum2) << endl;
    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while(t--)

    {

        int n, l,r;

        cin >> n >> l >> r;

        l-=1;

        r-=1;

        int arr[n];

        vector <long long int> arr1, arr2;

        for(int i=0;i<n;i++)

        {

            cin >> arr[i];

            if(i<l)

            arr1.push_back(arr[i]);

            else if(i>r)

            arr2.push_back(arr[i]);

            else

            {

                arr1.push_back(arr[i]);

                arr2.push_back(arr[i]);

            }

        }

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

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

        long long int sum1=0, sum2=0;

        for(int i=0;i<r-l;i++)

        {

            sum1+=arr1[i];

            sum2+=arr2[i];

        }

        cout << min(sum1, sum2) << endl;

    }

}

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while(t--)

    {

        int n, l,r;

        cin >> n >> l >> r;

        l-=1;

        r-=1;

        int arr[n];

        vector <long long int> arr1, arr2;

        for(int i=0;i<n;i++)

        {

            cin >> arr[i];

            if(i<l)

            arr1.push_back(arr[i]);

            else if(i>r)

            arr2.push_back(arr[i]);

            else

            {

                arr1.push_back(arr[i]);

                arr2.push_back(arr[i]);

            }

        }

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

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

        long long int sum1=0, sum2=0;

        for(int i=0;i<r-l+1;i++)

        {

            sum1+=arr1[i];

            sum2+=arr2[i];

        }

        cout << min(sum1, sum2) << endl;

    }

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

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, l,r;
        cin >> n >> l >> r;
        l-=1;
        r-=1;
        int arr[n];
        vector <int> arr1, arr2;
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            if(i<l)
            arr1.push_back(arr[i]);
            else if(i>r)
            arr2.push_back(arr[i]);
            else
            {
                arr1.push_back(arr[i]);
                arr2.push_back(arr[i]);
            }
        }
        sort(arr1.begin(), arr1.end());
        sort(arr2.begin(), arr2.end());
        long long int sum1=accumulate(arr1.begin(), arr1.begin()+r-l+1,0);
        long long int sum2=accumulate(arr2.begin(), arr2.begin()+r-l+1,0);
        cout << min(sum1, sum2) << endl;
    }
}

Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, l,r;
        cin >> n >> l >> r;
        l-=1;
        r-=1;
        int arr[n];
        vector <long long int> arr1, arr2;
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            if(i<l)
            arr1.push_back(arr[i]);
            else if(i>r)
            arr2.push_back(arr[i]);
            else
            {
                arr1.push_back(arr[i]);
                arr2.push_back(arr[i]);
            }
        }
        sort(arr1.begin(), arr1.end());
        sort(arr2.begin(), arr2.end());
        long long int sum1=accumulate(arr1.begin(), arr1.begin()+r-l+1,0);
        long long int sum2=accumulate(arr2.begin(), arr2.begin()+r-l+1,0);
        cout << min(sum1, sum2) << 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;

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n == 1) {
            cin >> n;
            cout << n << endl;
            continue;
        }
        vector<long long> l(n);
        long long r = 0;
        for(int i = 0; i < n; i++) {
            cin >> l[i];
            r += l[i];
        }
        while(l.size() > 1) {
            long long c = 0;
            for(int i = 0; i + 1 < n; i++) {
                l[i] -= l[i + 1];
                c += l[i];
            }
            l.pop_back();
            r = abs(c) > r ? abs(c) : r;
        }
        cout << (abs(l[0]) > r ? abs(l[0]) : r) << endl;
    }
}

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n == 1) {
            cin >> n;
            cout << n << endl;
            continue;
        }
        vector<long long> l(n);
        long long r = 0;
        for(int i = 0; i < n; i++) {
            cin >> l[i];
            r += l[i];
        }
        while(l.size() > 1) {
            long long c = 0;
            for(int i = 0; i + 1 < l.size(); i++) {
                l[i] -= l[i + 1];
                c += l[i];
            }
            l.pop_back();
            r = abs(c) > r ? abs(c) : r;
        }
        cout << (abs(l[0]) > r ? abs(l[0]) : r) << endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


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

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n == 1) {
            cin >> n;
            cout << n << endl;
            continue;
        }
        vector<long> l(n);
        long r = 0;
        for(int i = 0; i < n; i++) {
            cin >> l[i];
            r += l[i];
        }
        while(l.size() > 1) {
            long c = 0;
            for(int i = 0; i + 1 < n; i++) {
                l[i] -= l[i + 1];
                c += l[i];
            }
            l.pop_back();
            r = abs(c) > r ? abs(c) : r;
        }
        cout << (abs(l[0]) > r ? abs(l[0]) : r) << 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;

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n == 1) {
            cin >> n;
            cout << n << endl;
            continue;
        }
        vector<long> l(n);
        long r = 0;
        for(int i = 0; i < n; i++) {
            cin >> l[i];
            r += l[i];
        }
        while(l.size() > 1) {
            long c = 0;
            for(int i = 0; i + 1 < n; i++) {
                l[i] -= l[i + 1];
                c += l[i];
            }
            l.pop_back();
            r = abs(c) > r ? abs(c) : r;
        }
        cout << (abs(l[0]) > r ? abs(l[0]) : r) << endl;
    }
}

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n == 1) {
            cin >> n;
            cout << n << endl;
            continue;
        }
        vector<long long> l(n);
        long long r = 0;
        for(int i = 0; i < n; i++) {
            cin >> l[i];
            r += l[i];
        }
        while(l.size() > 1) {
            long long c = 0;
            for(int i = 0; i + 1 < n; i++) {
                l[i] -= l[i + 1];
                c += l[i];
            }
            l.pop_back();
            r = abs(c) > r ? abs(c) : r;
        }
        cout << (abs(l[0]) > r ? abs(l[0]) : r) << endl;
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


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

#define CNO cout << "NO\n"

#define CYES cout << "YES\n"

#define endl '\n'

#define ls id << 1

#define rs id << 1 | 1

#define llen (mid - l + 1)

#define rlen (r - mid)

using namespace std;

using ll = long long;

using uint = unsigned int;

using ull = unsigned long long;

using ld = long double;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

const ll mod = 998244353;

const int N = 1010;

int n, arr[N], h[N];

bool vis[N] = { 0 };

ll ans = 0;

string str;

vector<pii> v;



template <class T>

void chmax(T &a, T b) {

    if (a < b)

        a = b;

}



template <class T>

void chmin(T &a, T b) {

    if (a > b)

        a = b;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);

    int T = 1;

    // cin >> T;

    while (T--) {

        cin >> n;

        for (int i = 1; i <= n; ++i) {

            cin >> arr[i];

            vis[i] = 0;

        }

        iota(h + 1, h + n + 1, 1);

        for (int i = 1; i <= n; ++i) {

            if (vis[h[i]])

                continue;

            vis[h[i]] = 1;

            int p = i;

            for (int j = i - 1; j >= 1; --j) {

                v.push_back({ h[j + 1], h[j] });

                swap(h[j], h[j + 1]);

            }

            for (int j = 1; j < i; ++j) {

                v.push_back({ h[j + 1], h[j] });

                swap(h[j], h[j + 1]);

            }

            while (h[p] != arr[p]) {

                v.push_back({ h[p + 1], h[p] });

                swap(h[p], h[p + 1]);

                p++;

            }

            if (h[i] != arr[i])

                i--;

        }

        cout << v.size() << endl;

        for (auto i : v) cout << i.first << " " << i.second << endl;

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <algorithm>
#include <array>
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    unordered_multiset<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.insert(val);
    }

    unordered_multiset<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.insert(val);
    }

    
    while (!b.empty()) {
        int c = *b.begin();
        b.erase(b.begin());
        // cout << "Checking c " << c << "\n";
        auto it = a.find(c);
        if (it != a.end()) {
            a.erase(it);
            continue;
        }
        // cout << "not found in a\n";
        if (c == 1) {
            cout << "No\n";
            return ;
        }
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.insert(c1);
        b.insert(c2);
        // cout << "Insertint " << c1 << " " << c2 << "\n";
    }
    // Print output
    if (a.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 28):
#include <algorithm>
#include <array>
#include <iostream>
#include <unordered_set>
#include <set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    unordered_multiset<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.insert(val);
    }

    multiset<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.insert(val);
    }

    
    while (!b.empty()) {
        int c = *b.begin();
        b.erase(b.begin());
        // cout << "Checking c " << c << "\n";
        auto it = a.find(c);
        if (it != a.end()) {
            a.erase(it);
            continue;
        }
        // cout << "not found in a\n";
        if (c == 1) {
            cout << "No\n";
            return ;
        }
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.insert(c1);
        b.insert(c2);
        // cout << "Insertint " << c1 << " " << c2 << "\n";
    }
    // Print output
    if (a.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}

Submission (verdict: Accepted):
#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.push(val);
    }

    priority_queue<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.push(val);
    }

    
    while (!b.empty() && !a.empty()) {
        // cout << a.top() << " " << b.top() << endl;
        if (a.top() > b.top() || a.size() < b.size()) {
            cout << "No\n";
            return ;    
        }
        if (a.top() == b.top()) {
            a.pop(); b.pop();
            continue;
        }
        int c = b.top();
        b.pop();
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.push(c1);
        b.push(c2);
    }
    // Print output
    if (a.empty() && b.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <algorithm>
#include <array>
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    unordered_multiset<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.insert(val);
    }

    unordered_multiset<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.insert(val);
    }

    
    while (!b.empty()) {
        int c = *b.begin();
        b.erase(b.begin());
        // cout << "Checking c " << c << "\n";
        auto it = a.find(c);
        if (it != a.end()) {
            a.erase(it);
            continue;
        }
        // cout << "not found in a\n";
        if (c == 1) {
            cout << "No\n";
            return ;
        }
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.insert(c1);
        b.insert(c2);
        // cout << "Insertint " << c1 << " " << c2 << "\n";
    }
    // Print output
    if (a.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}

Submission (verdict: Time limit exceeded on test 28):
#include <algorithm>
#include <array>
#include <iostream>
#include <unordered_set>
#include <set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    unordered_multiset<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.insert(val);
    }

    multiset<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.insert(val);
    }

    
    while (!b.empty()) {
        int c = *b.begin();
        b.erase(b.begin());
        // cout << "Checking c " << c << "\n";
        auto it = a.find(c);
        if (it != a.end()) {
            a.erase(it);
            continue;
        }
        // cout << "not found in a\n";
        if (c == 1) {
            cout << "No\n";
            return ;
        }
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.insert(c1);
        b.insert(c2);
        // cout << "Insertint " << c1 << " " << c2 << "\n";
    }
    // Print output
    if (a.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    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 <algorithm>

#include <array>

#include <iomanip>

#include <iostream>

#include <cmath>

#include <cstdint>

#include <numeric>

#include <map>

#include <set>

#include <string>

#include <vector>



using namespace std;



int min_sum(const vector<int>& lr, const vector<int>& other) {

    int diff = 0;



    for (int i = 0; i < min(lr.size(), other.size()); i++) {

        // cout << "loop: " << other[i] << " " << lr[i] << endl;

        if (other[i] < lr[i]) diff += (lr[i] - other[i]);

    }

    // cout << diff << endl;

    return diff;

}

void solve() {

    // Read input

    int n, l, r;

    cin >> n >> l >> r;

    l--; r--;

    vector<int> a(n);

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

        cin >> a[i];

    }



    // Solve the problem here

    vector<int> lr;

    for (int i = l; i <= r; i++) {

        lr.push_back(a[i]);

    }

    sort(lr.begin(), lr.end(), std::greater<int>());



    int sum = accumulate(lr.begin(), lr.end(), 0);

    // cout << sum << endl;

    vector<int> bl;

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

        bl.push_back(a[i]);

    }

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



    vector<int> ar;

    for (int i = r + 1; i < n; i++) {

        ar.push_back(a[i]);

    }

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



    sum = min(sum, sum - min_sum(lr, bl));

    sum = min(sum, sum - min_sum(lr, ar));

    // Print output

    cout << sum << endl;

}



int main() {

    // freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout << setprecision(10);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length()
    a = 2**k - 1
    b = 2**k
    c = l
    print(a,b,c)

Submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length() - 1
    a = 2**k - 1
    b = 2**k
    c = l
    print(a,b,c)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length() - 1
    a = 2**k - 1
    b = 2**k
    for c in range(l,r+1):
        if c != a and c!= b:
            print(a,b,c)
            break

Submission (verdict: Accepted):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = (l ^ r).bit_length() - 1
    a = l|(2**k-1)
    b = a + 1
    for c in range(l,r+1):
        if c != a and c!= b:
            print(a,b,c)
            break
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length()
    a = 2**k - 1
    b = 2**k
    c = l
    print(a,b,c)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length() - 1
    a = 2**k - 1
    b = 2**k
    c = l
    print(a,b,c)

Submission (verdict: Wrong answer on test 1):
t = int(input())

for _ in range(t):
    l,r = map(int,input().split())
    k = r.bit_length() - 1
    a = 2**k - 1
    b = 2**k
    for c in range(l,r+1):
        if c != a and c!= b:
            print(a,b,c)
            break
Problem: 2062C - Cirno and Operations
Language: Python 3

Previous submission (verdict: Wrong answer on test 6):
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))


    def reduction(n, l):
        new_l = []
        summ=0
        for i in range(n - 1):
            new_l.append(l[i + 1] - l[i])
            summ += l[i+1]-l[i]
        return n - 1, new_l, summ


    def two(l):
        if l[0] * l[1] >= 0:
            return abs(l[0] + l[1])
        else:
            return abs(l[0] - l[1])

    if n==1:
        print(l[0])

    elif n==2:
        if l[0] >= 0 and l[1] >= 0:
            print(l[0] + l[1])
        else:
            print(abs(l[0] - l[1]))


    else:
        count =0
        while n >2:
            n, l, summ = reduction(n,l)
            count = max(count, abs(summ))
        print(max(two(l),count))


Submission (verdict: Accepted):
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))


    def reduction(n, l):
        new_l = []
        summ=0
        for i in range(n - 1):
            new_l.append(l[i + 1] - l[i])
            summ += l[i+1]-l[i]
        return n - 1, new_l, summ


    def two(l):
        if l[0] * l[1] >= 0:
            return abs(l[0] + l[1])
        else:
            return abs(l[0] - l[1])

    if n==1:
        print(l[0])

    elif n==2:
        if l[0] >= 0 and l[1] >= 0:
            print(l[0] + l[1])
        else:
            print(abs(l[0] - l[1]))


    else:
        count =sum(l)
        while n >2:
            n, l, summ = reduction(n,l)
            count = max(count, abs(summ))
            
        print(max(two(l),count))
Problem: 2062C - Cirno and Operations
Language: Python 3


Submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))


    def reduction(n, l):
        new_l = []
        for i in range(n - 1):
            new_l.append(l[i + 1] - l[i])
        return n - 1, new_l


    def two(l):
        if l[0] * l[1] >= 0:
            return abs(l[0] + l[1])
        else:
            return abs(l[0] - l[1])

    if n==1:
        print(l[0])

    else:
        while n >2:
            n, l = reduction(n,l)
        print(two(l))