ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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

#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;

string modify(string& s, int ind) {
    if (s[ind]!='0' && ind!=0) {
        int x=s[ind]-'0';
        x--;
        s[ind] = '0' + x;
        swap(s[ind], s[ind-1]);
    }
    return s;
}
// 11455
// 13155

string move (string& s, int start, int end) {
    int x=0;
    for (int i=end;i>start;i--) {
        s = modify(s, i);
    }
    return s;
}

void solve() {
    string s;
    cin >> s;

    // cout<<move(s,1,3)<<endl;


    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }

    } 
    cout<<s<<endl;
    
}

signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}


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

#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;



string move (string& s, int start, int end) {
    int x=s[end]-'0';
    x-=(end-start);

    // string temp = s.substr(0, start);
    // temp+= '0'+x;
    // temp+=s.substr(start, end);
    // // temp+=s.substr(end+1);

    s.insert(start, 1, '0'+x);
    s.erase(end+1, 1);
    return s;
}

void solve() {
    string s;
    cin >> s;

    // cout<<move(s,1,3)<<endl;


    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }

    } 
    cout<<s<<endl;
    
}

signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


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

#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;

string modify(string& s, int ind) {
    if (s[ind]!='0' && ind!=0) {
        int x=s[ind]-'0';
        x--;
        s[ind] = '0' + x;
        swap(s[ind], s[ind-1]);
    }
    return s;
}
// 11455
// 13155

string move (string& s, int start, int end) {
    int x=0;
    for (int i=end;i>start;i--) {
        s = modify(s, i);
    }
    return s;
}

void solve() {
    string s;
    cin >> s;

    // cout<<move(s,1,3)<<endl;


    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }

    } 
    cout<<s<<endl;
    
}

signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
/*
    author: Alphabet
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;
vector<vector<int>> graph;
int degree[100100];
int visited[100100];
void dfs(int level){
    if(visited[level]) return ;
    visited[level] = 1;
    for(auto v:graph[level]){
        degree[level]++;
        dfs(v);
    }
}
void solve(){
    int n;
    cin >> n;
    graph.resize(n+1);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    memset(degree, 0 , sizeof(degree));
    memset(visited, 0, sizeof(degree));

    for(int i=1; i<=n; i++){
        if(visited[i] == 0){
            dfs(i);
        }
    }

    vector<pair<int, int>> deg;
    for(int i=1; i<=n; i++){
        deg.push_back({-degree[i] , i});
    }
    sort(deg.begin(), deg.end());

    
    int fin = -1;
    if( -deg[0].first == n-1){
        fin = max(fin, n-2);
        cout << fin <<'\n';
        return;
    }
    int ans = -deg[0].first - 1;
    int ans1 = -deg[1].first;
    for(auto v: graph[deg[0].second]){
        if(v == deg[1].second){
            fin = max(fin, ans + ans1 -1);
        }
    }

    if(n>=3 && deg[2].first == deg[1].first){
        fin = max(fin ,ans + ans1); 
    }

    cout << fin <<'\n';
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
        graph.clear();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
/*
    author: Alphabet
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;
vector<vector<int>> graph;
int degree[100100];
int visited[100100];
void dfs(int level){
    if(visited[level]) return ;
    visited[level] = 1;
    for(auto v:graph[level]){
        degree[level]++;
        dfs(v);
    }
}
void solve(){
    int n;
    cin >> n;
    graph.resize(n+1);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    memset(degree, 0 , sizeof(degree));
    memset(visited, 0, sizeof(degree));

    for(int i=1; i<=n; i++){
        if(visited[i] == 0){
            dfs(i);
        }
    }

    vector<pair<int, int>> deg;
    for(int i=1; i<=n; i++){
        deg.push_back({-degree[i] , i});
    }
    sort(deg.begin(), deg.end());

    
    int fin = -1;
    if( -deg[0].first == n-1){
        fin = max(fin, n-2);
        cout << fin <<'\n';
        return;
    }
    int ans = -deg[0].first - 1;
    int ans1 = -deg[1].first;
    for(auto v: graph[deg[0].second]){
        if(v == deg[1].second){
            fin = max(fin, ans + ans1 -1);
        }
    }

    if(n>=3 && deg[2].first == deg[1].first){
        fin = max(fin ,ans + ans1); 
    }

    cout << fin <<'\n';
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
        graph.clear();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
/*
    author: Alphabet
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;
vector<vector<int>> graph;
int degree[200100];
int visited[200100];
void dfs(int level){
    if(visited[level]) return ;
    visited[level] = 1;
    for(auto v:graph[level]){
        degree[level]++;
        dfs(v);
    }
}
void solve(){
    int n;
    cin >> n;
    graph.resize(n+1);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    memset(degree, 0 , sizeof(degree));
    memset(visited, 0, sizeof(degree));

    for(int i=1; i<=n; i++){
        if(visited[i] == 0){
            dfs(i);
        }
    }

    vector<pair<int, int>> deg;
    for(int i=1; i<=n; i++){
        deg.push_back({-degree[i] , i});
    }
    sort(deg.begin(), deg.end());

    
    int fin = -1;
    int ans = -deg[0].first;
    vector<int> arr;
    for(int i=1; i<=n; i++){
        if(deg[i].first == deg[1].first){
            arr.push_back(deg[i].second);
        }
    }

    set<int> st;
    for(auto v: graph[deg[0].second]){
        st.insert(v);
    }
    for(auto v: arr){
        if(st.find(v) == st.end()){
            fin = max(fin, ans - deg[1].first - 1);
        }
    }
    
    fin = max(fin, ans - deg[1].first - 2);
    cout << fin <<'\n';
    graph.clear();
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
#define N cout << "No\n"
#define Y cout << "Yes\n"
#define endl '\n'
#define all(a) a.begin(),a.end()
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve() {
    int n;
    cin >> n;
    vector <vector <int>> a(n+1);
    for (int i=1; i<n; i++) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    if (n == 2) {
        cout << 0 << endl;
    } else if (n == 3){
        cout << 1 << endl;
    } else if (n == 4) {
        cout << 2 << endl;
    } else {
        int sum = 1;
        vector <int> num(n+1);
        for (int i=1; i<=n; i++) {
            num[i] = a[i].size();
        }
        sort(all(num));
        for (int i=n; i>=n-1; i--) {
            sum += num[i] - 1;
        }
        cout << sum << endl;
    }
}

signed main ()
{
    IOS;
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
#define N cout << "No\n"
#define Y cout << "Yes\n"
#define endl '\n'
#define all(a) a.begin(),a.end()
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve() {
    int n;
    cin >> n;
    vector <vector <int>> a(n+1);
    for (int i=1; i<n; i++) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    if (n == 2) {
        cout << 0 << endl;
    } else if (n == 3){
        cout << 1 << endl;
    } else if (n == 4) {
        cout << 2 << endl;
    } else {
        int res = 1;
        vector <pair <int, int>> num(n+1);
        for (int i=1; i<=n; i++) {
            num[i].first = a[i].size();
            num[i].second = i;
        }
        sort(all(num));
        res += num[n].first - 1;
        vector <pair <int, int>> kk(n+1);
        for (int i=1; i<=n; i++) {
            if (i == num[n].second) {
                continue;
            }
            kk[i].first = a[i].size();
            kk[i].second = i;
        }
        for (auto x : a[num[n].second]) {
            kk[x].first--;
        }
        sort(all(kk));
        res += kk[n].first - 1;
        cout << res << endl;
    }
}

signed main ()
{
    IOS;
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
#define N cout << "No\n"
#define Y cout << "Yes\n"
#define endl '\n'
#define all(a) a.begin(),a.end()
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve() {
    int n;
    cin >> n;
    vector <vector <int>> a(n+1);
    for (int i=1; i<n; i++) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    if (n == 2) {
        cout << 0 << endl;
    } else if (n == 3){
        cout << 1 << endl;
    } else if (n == 4) {
        cout << 2 << endl;
    } else {
        int sum = 1;
        vector <int> num(n+1);
        for (int i=1; i<=n; i++) {
            num[i] = a[i].size();
        }
        sort(all(num));
        for (int i=n; i>=n-1; i--) {
            sum += num[i] - 1;
        }
        cout << sum << endl;
    }
}

signed main ()
{
    IOS;
    int t = 1;
    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;

int main() {
    int t;
    cin >> t; // Number of test cases

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

        vector<int> arr(n);
        for (int i = 0; i < n; i++) {
            cin >> arr[i]; // Input array
        }

        vector<int> brr(n); 
        
        if(n==1){
            cout<<arr[0]<<endl;
        }else{
        for (int i = 0; i < n; i++) { // Process at most n-1 times
            int sum = 0;
            for (int j = 0; j < n - i; j++) {
                sum += arr[j]; // Compute sum of first (n-i) elements
            }
            if(i==0){
                brr.push_back(sum);
            }else{

                brr.push_back(abs(sum));
            }

            // Compute new difference array, ensuring no out-of-bounds
            for (int j = 0; j < n - i - 1; j++) {
                arr[j] = arr[j + 1] - arr[j]; // Safe transformation
            }
        }

        if (!brr.empty()) {
            int max_value = *max_element(brr.begin(), brr.end());
            cout << max_value << endl;
        }
    }
    }

    return 0;
}


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

int main() {
    int t;
    cin >> t; // Number of test cases

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

        vector<long long> arr(n);
        for (int i = 0; i < n; i++) {
            cin >> arr[i]; // Input array
        }

        vector<long long> brr(n); 
        
        if(n==1){
            cout<<arr[0]<<endl;
        }else{
        for (int i = 0; i < n; i++) { // Process at most n-1 times
            long long sum = 0;
            for (int j = 0; j < n - i; j++) {
                sum += arr[j]; // Compute sum of first (n-i) elements
            }
            if(i==0){
                brr.push_back(sum);
            }else{

                brr.push_back(abs(sum));
            }

            // Compute new difference array, ensuring no out-of-bounds
            for (int j = 0; j < n - i - 1; j++) {
                arr[j] = arr[j + 1] - arr[j]; // Safe transformation
            }
        }

        if (!brr.empty()) {
            long long max_value = *max_element(brr.begin(), brr.end());
            cout << max_value << endl;
        }
    }
    }

    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;

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

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

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

        vector<int> brr(n);
        
        if(n == 1){
            cout<<arr[0]<<endl;
        }else{
        for (int i = 0; i < n; i++) { 
            int sum = 0;
            for (int j = 0; j < n - i; j++) {
                sum += arr[j];
            }

            brr.push_back(abs(sum));
            for (int j = 0; j < n - i - 1; j++) {
                arr[j] = arr[j + 1] - arr[j]; 
            }
        }

        if (!brr.empty()) {
            int max_value = *max_element(brr.begin(), brr.end());
            cout << max_value << endl;
        }
    }
    }

    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;

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

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

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

        vector<int> brr(n);
        
        if(n == 1){
            cout<<arr[0]<<endl;
        }else{
        for (int i = 0; i < n; i++) { 
            int sum = 0;
            for (int j = 0; j < n - i; j++) {
                sum += arr[j];
            }

            brr.push_back(abs(sum));
            for (int j = 0; j < n - i - 1; j++) {
                arr[j] = arr[j + 1] - arr[j]; 
            }
        }

        if (!brr.empty()) {
            int max_value = *max_element(brr.begin(), brr.end());
            cout << max_value << endl;
        }
    }
    }

    return 0;
}


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

int main() {
    int t;
    cin >> t; // Number of test cases

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

        vector<int> arr(n);
        for (int i = 0; i < n; i++) {
            cin >> arr[i]; // Input array
        }

        vector<int> brr(n); 
        
        if(n==1){
            cout<<arr[0]<<endl;
        }else{
        for (int i = 0; i < n; i++) { // Process at most n-1 times
            int sum = 0;
            for (int j = 0; j < n - i; j++) {
                sum += arr[j]; // Compute sum of first (n-i) elements
            }
            if(i==0){
                brr.push_back(sum);
            }else{

                brr.push_back(abs(sum));
            }

            // Compute new difference array, ensuring no out-of-bounds
            for (int j = 0; j < n - i - 1; j++) {
                arr[j] = arr[j + 1] - arr[j]; // Safe transformation
            }
        }

        if (!brr.empty()) {
            int max_value = *max_element(brr.begin(), brr.end());
            cout << max_value << endl;
        }
    }
    }

    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;


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		int arr[n];
		long long sum = 0;
		for (int i = 0; i < n; ++i) cin >> arr[i];
		sort(arr, arr+n);
		for (int i = 0; i <= r - l; ++i) sum += arr[i];
		cout << sum << "\n";
	}
	return 0;
}


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

using namespace std;





int main() {

	ios::sync_with_stdio(0); cin.tie(0);

	int t; cin >> t;

	while (t--) {

		int n, l, r;

		cin >> n >> l >> r;

		--l; --r;

		int a[n], b[n];

		long long suma = 0, sumb = 0;

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

		sort(a, a+r+1); sort(b+l, b+n);

		for (int i = 0; i < r-l+1; ++i) suma += a[i];

		for (int i = l; i <= r; ++i) sumb += b[i];

		cout << min(suma, sumb) << "\n";

	}

	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;


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		int arr[n], sum = 0;
		for (int i = 0; i < n; ++i) cin >> arr[i];
		sort(arr, arr+n);
		for (int i = 0; i <= r - l; ++i) sum += arr[i];
		cout << sum << "\n";
	}
	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;


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		int arr[n], sum = 0;
		for (int i = 0; i < n; ++i) cin >> arr[i];
		sort(arr, arr+n);
		for (int i = 0; i <= r - l; ++i) sum += arr[i];
		cout << sum << "\n";
	}
	return 0;
}


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


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		int arr[n];
		long long sum = 0;
		for (int i = 0; i < n; ++i) cin >> arr[i];
		sort(arr, arr+n);
		for (int i = 0; i <= r - l; ++i) sum += arr[i];
		cout << sum << "\n";
	}
	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>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), ans += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		for (; n > 1; --n) {
			sum = 0;
			for (int i = 1; i < n; i++)
				sum += (a[i] = a[i + 1] - a[i]);
			ans = max(ans, abs(sum));
		}
		printf("%d\n", ans);
	}
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51], b[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), ans += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		for (; n > 1; ) {
			sum = 0;
			for (int i = 1; i < n; i++)
				b[i] = a[i + 1] - a[i], sum += b[i];
			ans = max(ans, abs(sum));
			--n;
			for (int i = 1; i <= n; i++)
				a[i] = b[i];
		}
		printf("%d\n", ans);
	}
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51], b[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), ans += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		for (; n > 1; ) {
			sum = 0;
			for (int i = 1; i < n; i++)
				b[i] = a[i + 1] - a[i], sum += b[i];
			ans = max(ans, abs(sum));
			--n;
			for (int i = 1; i <= n; i++)
				a[i] = b[i];
		}
		printf("%d\n", ans);
	}
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), ans += a[i];
		for (; --n; ) {
			sum = 0;
			for (int i = 1; i <= n; i++)
				a[i] -= a[i + 1], sum += a[i];
			ans = max(ans, abs(sum));
		}
		printf("%d\n", ans);
	}
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		sum = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), sum += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		ans = abs(sum);
		for (; n > 1; --n) {
			sum = 0;
			for (int i = 1; i < n; i++)
				sum += (a[i] = a[i + 1] - a[i]);
			ans = max(ans, abs(sum));
		}
		printf("%d\n", ans);
	}
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int _, n, ans, sum, a[51];
int main() {
	scanf("%d", &_);
	for (; _--; ) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", &a[i]), ans += a[i];
		if (n == 1) {
			printf("%d\n", a[1]);
			continue;
		}
		for (; n > 1; --n) {
			sum = 0;
			for (int i = 1; i < n; i++)
				sum += (a[i] = a[i + 1] - a[i]);
			ans = max(ans, abs(sum));
		}
		printf("%d\n", ans);
	}
}