ShaysXIA/CodeInsightBench huggingface dataset:
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 int long long
#define endl '\n'
const int N = 2e5 + 10;
vector <vector<int>> s(N);
int cnt[N];

struct node
{
    int id;
    int size;
}l[N];

bool cmp(node a, node b)
{
    return a.size > b.size;
}

void solve()
{
    int n;
    std:: cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        s[i].clear();
        cnt[i] = 0;
    }

    for(int i = 1; i <= n - 1; i ++ )
    {
        int u, v;
        std:: cin >> u >> v;
        s[u].push_back(v);
        s[v].push_back(u);
    }

    for(int i = 1; i <= n; i ++ )
    {
        l[i].id = i;
        l[i].size = s[i].size();
        cnt[i] = l[i].size;
    }

    std:: sort(l + 1, l + 1 + n, cmp);

    int ans = 0;
    auto &x = l[1];
    ans += x.size;

    for(auto p : s[x.id])
    {
        cnt[p] -- ;
    }
    int flag = x.id;

    int ct = 0;
    for(int i = 1; i <= n; i ++ )
    {
        if(i == flag) continue;
        l[++ ct].id = i;
        l[ct].size = cnt[i];
    }

    std:: sort(l + 1, l + ct + 1, cmp);
    auto &y = l[1];
    ans += y.size;
    if(y.size == 1)
    {
        std:: cout << ans << endl;
    }
    else
    std:: cout << ans - 1 << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    std:: cin >> T;
    while(T -- )
    solve();
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 2e5 + 10;
vector <vector<int>> s(N);
int cnt[N];
int h[N];
struct node
{
    int id;
    int size;
    int h;
}l[N];

bool cmp(node a, node b)
{
    if(a.size == b.size)
    {
        return a.h > b.h;
    }
    return a.size > b.size;
}

void dfs(int u, int fa, int high)
{
    h[u] = high;
    for(int i = 0; i < s[u].size(); i ++ )
    {
        int j = s[u][i];
        if(j == fa) continue;
        dfs(j, u, high + 1);
    }
}

void solve()
{
    int n;
    std:: cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        s[i].clear();
        cnt[i] = 0;
    }

    for(int i = 1; i <= n - 1; i ++ )
    {
        int u, v;
        std:: cin >> u >> v;
        s[u].push_back(v);
        s[v].push_back(u);
    }

    dfs(1, 0, 1);

    for(int i = 1; i <= n; i ++ )
    {
        l[i].id = i;
        l[i].size = s[i].size();
        l[i].h = h[i];
        cnt[i] = l[i].size;
    }

    std:: sort(l + 1, l + 1 + n, cmp);

    int ans = 0;
    auto &x = l[1];
    ans += x.size;

    for(auto p : s[x.id])
    {
        cnt[p] -- ;
    }
    int flag = x.id;

    int ct = 0;
    for(int i = 1; i <= n; i ++ )
    {
        if(i == flag) continue;
        l[++ ct].id = i;
        l[ct].size = cnt[i];
        l[ct].h = h[i];
    }

    std:: sort(l + 1, l + ct + 1, cmp);
    auto &y = l[1];
    ans += y.size;
    std:: cout << ans - 1 << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    std:: 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 int long long
#define endl '\n'
const int N = 2e5 + 10;
vector <vector<int>> s(N);
int cnt[N];

struct node
{
    int id;
    int size;
}l[N];

bool cmp(node a, node b)
{
    return a.size > b.size;
}

void solve()
{
    int n;
    std:: cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        s[i].clear();
        cnt[i] = 0;
    }

    for(int i = 1; i <= n - 1; i ++ )
    {
        int u, v;
        std:: cin >> u >> v;
        s[u].push_back(v);
        s[v].push_back(u);
    }

    for(int i = 1; i <= n; i ++ )
    {
        l[i].id = i;
        l[i].size = s[i].size();
        cnt[i] = l[i].size;
    }

    std:: sort(l + 1, l + 1 + n, cmp);

    int ans = 0;
    auto &x = l[1];
    ans += x.size;

    for(auto p : s[x.id])
    {
        cnt[p] -- ;
    }
    int flag = x.id;

    int ct = 0;
    for(int i = 1; i <= n; i ++ )
    {
        if(i == flag) continue;
        l[++ ct].id = i;
        l[ct].size = cnt[i];
    }

    std:: sort(l + 1, l + ct + 1, cmp);
    auto &y = l[1];
    ans += y.size;
    std:: cout << ans - 1 << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    std:: 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 int long long
#define endl '\n'
const int N = 2e5 + 10;
vector <vector<int>> s(N);
int cnt[N];

struct node
{
    int id;
    int size;
}l[N];

bool cmp(node a, node b)
{
    return a.size > b.size;
}

void solve()
{
    int n;
    std:: cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        s[i].clear();
        cnt[i] = 0;
    }

    for(int i = 1; i <= n - 1; i ++ )
    {
        int u, v;
        std:: cin >> u >> v;
        s[u].push_back(v);
        s[v].push_back(u);
    }

    for(int i = 1; i <= n; i ++ )
    {
        l[i].id = i;
        l[i].size = s[i].size();
        cnt[i] = l[i].size;
    }

    std:: sort(l + 1, l + 1 + n, cmp);

    int ans = 0;
    auto &x = l[1];
    ans += x.size;

    for(auto p : s[x.id])
    {
        cnt[p] -- ;
    }
    int flag = x.id;

    int ct = 0;
    for(int i = 1; i <= n; i ++ )
    {
        if(i == flag) continue;
        l[++ ct].id = i;
        l[ct].size = cnt[i];
    }

    std:: sort(l + 1, l + ct + 1, cmp);
    auto &y = l[1];
    ans += y.size;
    std:: cout << ans - 1 << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    std:: cin >> T;
    while(T -- )
    solve();
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 2e5 + 10;
vector <vector<int>> s(N);
int cnt[N];

struct node
{
    int id;
    int size;
}l[N];

bool cmp(node a, node b)
{
    return a.size > b.size;
}

void solve()
{
    int n;
    std:: cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        s[i].clear();
        cnt[i] = 0;
    }

    for(int i = 1; i <= n - 1; i ++ )
    {
        int u, v;
        std:: cin >> u >> v;
        s[u].push_back(v);
        s[v].push_back(u);
    }

    for(int i = 1; i <= n; i ++ )
    {
        l[i].id = i;
        l[i].size = s[i].size();
        cnt[i] = l[i].size;
    }

    std:: sort(l + 1, l + 1 + n, cmp);

    int ans = 0;
    auto &x = l[1];
    ans += x.size;

    for(auto p : s[x.id])
    {
        cnt[p] -- ;
    }
    int flag = x.id;

    int ct = 0;
    for(int i = 1; i <= n; i ++ )
    {
        if(i == flag) continue;
        l[++ ct].id = i;
        l[ct].size = cnt[i];
    }

    std:: sort(l + 1, l + ct + 1, cmp);
    auto &y = l[1];
    ans += y.size;
    if(y.size == 1)
    {
        std:: cout << ans << endl;
    }
    else
    std:: cout << ans - 1 << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    std:: cin >> T;
    while(T -- )
    solve();
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    bool no= true;

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    f(i,0,tw+1){

        f(j,0,si+1){

            if((k+2*i+6*j)%9==0){

                cout<<"Yes"<<"\n";

                no=false;

                break;

            }

        }

    }

    if(no) cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}

Submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    bool no= true;

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

            if((k+2*i+6*j)%9==0){

                cout<<"Yes"<<"\n";

                no=false;

                break;

            }

        }

    }

    if(no) cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    bool no= true;

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    f(i,0,tw+1){

        f(j,0,si+1){

            if((k+2*i+6*j)%9==0){

                cout<<"Yes"<<"\n";

                no=false;

                break;

            }

        }

    }

    if(no) cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    bool no= true;

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

            if((k+2*i+6*j)%9==0){

                cout<<"Yes"<<"\n";

                no=false;

                break;

            }

        }

    }

    if(no) cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}

Submission (verdict: Accepted):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

            int v=(k+2*i+6*j);

            if(v%9==0){

                cout<<"Yes"<<"\n";

                

                return;

            }

        }

    }

    cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.length();







f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

int t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-

Submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.length();







f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

char t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string s;

cin>>s;

int n=s.length();

vector<int> a(n);

f(i,0,n) a[i]=s[i]-'0';



f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

int t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.length();







f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

char t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-

Submission (verdict: Accepted):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.size();







f(i,0,n){

int k=i;

f(j,i,min(n,i+10)){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

char t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string s;

cin>>s;

int n=s.length();

vector<int> a(n);

f(i,0,n) a[i]=s[i]-'0';



f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

int t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-

Submission (verdict: Time limit exceeded on test 6):
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.length();







f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

int t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



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;
typedef long long ll;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        if (n == 1) {
            cout << a[0] << endl; 
            continue;
        }
        int sum =0;
        for(int i=0;i<n;i++){
            sum+=a[i];
        }
        while (a.size() > 1) {
            vector<int> b; 
            for (int i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            a = b; 
        }
        
        cout << max(sum,abs(a[0])) << endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);  // Use long long to prevent type mismatch
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        if (n == 1) {
            cout << a[0] << endl; 
            continue;
        }

        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }

        while (a.size() > 1) {
            vector<ll> b; 
            sum+= max(sum,abs(a[n-1]-a[1]));
            for (size_t i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            a = b;  
        }
        
        cout << max(sum, abs(a[0])) << endl;
    }
    return 0;
}


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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);  
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        if (n == 1) {
            cout << a[0] << endl; 
            continue;
        }

        ll ans = 0;  // Store max encountered value
        for (int i = 0; i < n; i++) {
            ans += a[i];  // Initialize with sum of elements
        }

        while (a.size() > 1) {
            ans = max(ans, abs(a.back() - a[0]));  // Correct indexing
            
            vector<ll> b;
            for (size_t i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            a = b;  
        }
        
        cout << max(ans, abs(a[0])) << 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;
typedef long long ll;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);  // Use long long to prevent type mismatch
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        if (n == 1) {
            cout << a[0] << endl; 
            continue;
        }

        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }

        while (a.size() > 1) {
            vector<ll> b; 
            for (size_t i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            a = b;  
        }
        
        cout << max(sum, abs(a[0])) << endl;
    }
    return 0;
}


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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);  // Use long long to prevent type mismatch
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        if (n == 1) {
            cout << a[0] << endl; 
            continue;
        }

        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }

        while (a.size() > 1) {
            vector<ll> b; 
            sum+= max(sum,abs(a[n-1]-a[1]));
            for (size_t i = 0; i < a.size() - 1; i++) {
                b.push_back(a[i + 1] - a[i]);
            }
            a = b;  
        }
        
        cout << max(sum, abs(a[0])) << endl;
    }
    return 0;
}