ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long int

const int M = 1e5+7; 



bool divs(int sum,int index,vector<int> &v,vector<vector<int>> &dp){

	if(index<0) return sum%9==0;

	if(dp[index][sum]!=-1) return dp[index][sum];

	if(sum%9==0) return dp[index][sum]=1;

	// if(index==0) return dp[index][sum]=0;

	int a = v[index];

	bool ans1=0,ans2=0;

	if(a==2) ans2=divs(sum+2,index-1,v,dp);

	if(a==3) ans1=divs(sum+6,index-1,v,dp);

	return dp[index][sum]=(ans1||ans2||divs(sum,index-1,v,dp));

	}

int main() {

	int t;

	cin>>t;

	while(t--){



		string s;

		cin>>s;

		int n =s.size();

		vector<vector<int>> dp(n, vector<int>(10*n, -1));

		vector<int> v(s.size());

		for(int i=0;i<s.size();i++) v[i]=(s[i]-'0');

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

		bool ans = divs(sum,s.size()-1,v,dp);

		if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

			

	}

	return 0;

}



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

using namespace std;

#define ll long long int

const int M = 1e5+7; 



bool divs(int sum,int index,vector<int> &v,vector<int> &dp){

	if(index<0) return sum%9==0;

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

	if(sum%9==0) return dp[index]=1;

	int a = v[index];

	bool ans1=0,ans2=0;

	if(a==2) ans2=divs(sum+2,index-1,v,dp);

	if(a==3) ans1=divs(sum+6,index-1,v,dp);

	return dp[index]=(ans1||ans2||divs(sum,index-1,v,dp));

	}

int main() {

	int t;

	cin>>t;

	while(t--){

		string s;

		cin>>s;

		int n =s.size();

		vector<int> dp(n,-1);

		vector<int> v(s.size());

		for(int i=0;i<s.size();i++) v[i]=(s[i]-'0');

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

		bool ans = divs(sum,s.size()-1,v,dp);

		if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

			

	}

	return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

#define ll long long int

const int M = 1e5+7; 



bool divs(int sum,int index,vector<int> &v,vector<vector<int>> &dp){

	if(index<0) return sum%9==0;

	if(dp[index][sum]!=-1) return dp[index][sum];

	if(sum%9==0) return dp[index][sum]=1;

	// if(index==0) return dp[index][sum]=0;

	int a = v[index];

	bool ans1=0,ans2=0;

	if(a==2) ans2=divs(sum+2,index-1,v,dp);

	if(a==3) ans1=divs(sum+6,index-1,v,dp);

	return dp[index][sum]=(ans1||ans2||divs(sum,index-1,v,dp));

	}

int main() {

	int t;

	cin>>t;

	while(t--){



		string s;

		cin>>s;

		int n =s.size();

		vector<vector<int>> dp(n, vector<int>(10*n, -1));

		vector<int> v(s.size());

		for(int i=0;i<s.size();i++) v[i]=(s[i]-'0');

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

		bool ans = divs(sum,s.size()-1,v,dp);

		if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

			

	}

	return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long int

const int M = 1e5+7; 



bool divs(int sum,int index,vector<int> &v,vector<int> &dp){

	if(index<0) return sum%9==0;

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

	if(sum%9==0) return dp[index]=1;

	int a = v[index];

	bool ans1=0,ans2=0;

	if(a==2) ans2=divs(sum+2,index-1,v,dp);

	if(a==3) ans1=divs(sum+6,index-1,v,dp);

	return dp[index]=(ans1||ans2||divs(sum,index-1,v,dp));

	}

int main() {

	int t;

	cin>>t;

	while(t--){

		string s;

		cin>>s;

		int n =s.size();

		vector<int> dp(n,-1);

		vector<int> v(s.size());

		for(int i=0;i<s.size();i++) v[i]=(s[i]-'0');

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

		bool ans = divs(sum,s.size()-1,v,dp);

		if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

			

	}

	return 0;

}



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

using namespace std;

#define ll long long int

const int M = 1e5+7; 



bool divs(int sum,int index,vector<int> &v,vector<vector<int>> &dp){

	sum%=9;

	if(index<0) return sum%9==0;

	if(dp[index][sum]!=-1) return dp[index][sum];

	if(sum%9==0) return dp[index][sum]=1;

	// if(index==0) return dp[index][sum]=0;

	int a = v[index];

	bool ans1=0,ans2=0;

	if(a==2) ans2=divs(sum+2,index-1,v,dp);

	if(a==3) ans1=divs(sum+6,index-1,v,dp);

	return dp[index][sum]=(ans1||ans2||divs(sum,index-1,v,dp));

	}

int main() {

	int t;

	cin>>t;

	while(t--){



		string s;

		cin>>s;

		int n =s.size();

		vector<vector<int>> dp(n, vector<int>(10, -1));

		vector<int> v(s.size());

		for(int i=0;i<s.size();i++) v[i]=(s[i]-'0');

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

		sum%=9;

		bool ans = divs(sum,s.size()-1,v,dp);

		if(ans) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

			

	}

	return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int index= 8-num;

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

if(j>n-1) break;

if(charc(s[j])>(num+(j-i))){

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

perform(s,k);

}

break;

}

}

}

cout<<s<<endl;



}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int index= 8-num;

int max_inc =0;

int ind=-1;

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

if(j>n-1) break;

if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp>0) max_inc = max(max_inc,temp);}





}

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

if(j>n-1) break;

if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp==max_inc) {

ind=j;

break;

}

}



}

if (max_inc>0)for(int k=ind;k>i;k--){

perform(s,k);

}

}

cout<<s<<endl;



}

return 0;

}

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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int max_inc =0;

int ind=-1;

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

if(j>n-1) break;

// if(charc(s[j])<1) ;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp>0) max_inc = max(max_inc,temp);}





}

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

if(j>n-1) break;

// if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp==max_inc) {

ind=j;

break;

}

}



}

if (max_inc>0)for(int k=ind;k>i;k--){

perform(s,k);

}

}

cout<<s<<endl;



}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int max_inc =0;

int ind=-1;

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

if(j>n-1) break;

// if(charc(s[j])<1) ;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp>0) max_inc = max(max_inc,temp);}





}

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

if(j>n-1) break;

// if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp==max_inc) {

ind=j;

break;

}

}



}

if (max_inc>0)for(int k=ind;k>i;k--){

perform(s,k);

}

}

cout<<s<<endl;



}

return 0;

}

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

using namespace std;



int charc(char c) {

return c - '0';

}



// Performs one valid operation: decrease the digit and swap it left

void perform(string &s, int index) {

swap(s[index], s[index - 1]);

s[index - 1] = static_cast<char>(s[index - 1] - 1);

}



int main() {

int t;

cin >> t;



while (t--) {

string s;

cin >> s;

int n = s.size();



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

int best = -1, ind = -1;



// Check digits from index i to i+9 (or end of string)

for (int j = i; j <= min(n - 1, i + 9); ++j) {

int val = charc(s[j]) - (j - i);

if (val > best) {

best = val;

ind = j;

}

}



// If a better digit is found, move it to position i

if (ind != i) {

for (int k = ind; k > i; --k) {

perform(s, k);

}

}

}



cout << s << "\n";

}



return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int index= 8-num;

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

if(j>n-1) break;

if(charc(s[j])>(num+(j-i))){

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

perform(s,k);

}

break;

}

}

}

cout<<s<<endl;



}

return 0;

}

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

using namespace std;

#define ll long long int

const ll M = 1e18+7;

const int N = 1e5+7;





int charc(char c){

return c-'0';

}

void perform(string &s,int index){

int nums = charc(s[index]);

nums--;

char ab = static_cast<char>(48+nums);

s[index]=s[index-1];

s[index-1] = ab;



}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n = s.size();

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

if (charc(s[i])>7) continue;

int num = charc(s[i]);

int index= 8-num;

int max_inc =0;

int ind=-1;

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

if(j>n-1) break;

if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp>0) max_inc = max(max_inc,temp);}





}

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

if(j>n-1) break;

if(charc(s[j])<1) break;

if(charc(s[j])>(num+(j-i))){

int temp = charc(s[j])-(num+(j-i));

if(temp==max_inc) {

ind=j;

break;

}

}



}

if (max_inc>0)for(int k=ind;k>i;k--){

perform(s,k);

}

}

cout<<s<<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>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<int> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			int max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
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>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<int> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			int max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<int> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			ll max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,1LL*abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
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>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<int> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			ll max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,1LL*abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<ll> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			ll max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,1LL*abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
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>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<ll> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			ll max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,1LL*abs(accumulate(v.begin(),v.end(),0)));
			}
			cout<<max_sum<<endl;

		}
 
return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int M = 1e9+7; 


int main() {
		int t;
		cin>>t;
		while(t--){
			int n;
			cin>>n;
			vector<ll> v(n);
			for(int i=0;i<n;i++) cin>>v[i];

			ll max_sum = accumulate(v.begin(),v.end(),0);
			for(int j=n-1;j>0;j--){

				for(int i=0;i<j;i++){
					v[i] = v[i+1]-v[i];
				}
				v.pop_back();
				max_sum = max(max_sum,1LL*abs(accumulate(v.begin(),v.end(),0LL)));
			}
			cout<<max_sum<<endl;

		}
 
return 0;
}
Problem: 2063C - Remove Exactly Two
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
import sys,math,bisect,heapq
input=sys.stdin.readline
#remember file names are input.txt and output.txt 
#remember to pass only one argument to print
#add this lines before your program and after defining fast io(or that will over write testing)
#after testing done set flag =0
flag=0
if flag:
    class out:
        def __init__(self):
            self.fo=open("cp_with_python/cp/output.txt","w")
        def inu(self,*x):
            if str(type(x))!="<class 'str'>":
                x=str(x)
            self.fo.write(x)
            self.fo.write("\n")
    class inp:
        def __init__(self):
            self.fi=open("cp_with_python/cp/input.txt","r")
        def inu(self):
            return self.fi.readline()
    fy=out()
    print=fy.inu
    fx=inp()
    input=fx.inu

for _ in range(int(input())):
    n=int(input())
    #n,s1,s2=map(int,input().split())
    #a=list(map(int,input().split()))
    graph=[set() for i in range(n)]
    inc=[[i,0] for i in range(n)]
    for i in range(n-1):
        x,y=map(int,input().split())
        graph[x-1].add(y-1)
        graph[y-1].add(x-1)
        inc[x-1][1]+=1
        inc[y-1][1]+=1
    inc.sort(key=lambda x:x[1],reverse=True)
    ans=[0]*n
    if n==2:
        print(0)
    else:
        if inc[1][1]>inc[2][1]:
            if inc[1][0] in graph[inc[0][0]]:
                print(inc[0][1]+inc[1][1]-2)
            else:
                print(inc[0][1]+inc[1][1]-1)
        else:
            if inc[1][0] in graph[inc[0][0]]:
                if inc[2][0] in graph[inc[0][0]]:
                    print(max(inc[1][1]+inc[2][1]+1,inc[1][1]+inc[0][1])-2)
                else:
                    print(inc[0][1]+inc[2][1]-1)
            else:
                print(inc[0][1]+inc[1][1]-1)
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vi v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vi o(vi v) {
    if (v.size() == 1)return v;
    vi v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = 0;
    for (auto it: v)s += it;
    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
    } while (v1.size() > 1);

    cout << max(v1.back() * 1LL, s) << "\n";
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vi v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vi o(vi v) {
    if (v.size() == 1)return v;
    vi v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = 0;
    for (auto it: v)s += it;
    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
    } while (v1.size() > 1);

    cout << max(v1.back() * 1LL, s) << "\n";
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vector<long long> v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vector<long long> o(vector<long long> v) {
    if (v.size() == 1)return v;
    vector<long long> v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<long long> v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = 0;
    for (auto it: v)s += it;
    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
    } while (v1.size() > 1);

    cout << max(v1.back() * 1LL, s) << "\n";
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vector<long long> v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vector<long long> o(vector<long long> v) {
    if (v.size() == 1)return v;
    vector<long long> v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<long long> v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = 0;
    for (auto it: v)s += it;
    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
    } while (v1.size() > 1);

    cout << max(v1.back() * 1LL, s) << "\n";
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vector<long long> v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vector<long long> o(vector<long long> v) {
    if (v.size() == 1)return v;
    vector<long long> v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

long long sum(vector<long long> v) {
    long long s = 0;
    for (auto it: v)s += it;
    return s;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<long long> v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = sum(v);

    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
        s = max(s, sum(v));
    } while (v1.size() > 1);

    cout << s << "\n";
}