ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define MAX 10000
using namespace std;
unsigned long long SumDigits(char s[]){
    unsigned long long ans = 0 ;
    for(int i = 0 ;s[i]!= '\0'; i++){
        ans += s[i] -'0';
    }
    return ans;
}
int main(){
    int t; cin>>t;
    cin.ignore();
    int idx = 0;
    int res[10000] ;
    while(t--){
        bool ok = 1;
        char s[MAX] ;
        cin.getline(s,10000);
        int ans = SumDigits(s);
        if (ans % 9 == 0 ) {res[idx++] = 1; ok = 0;}
        for(int i = 0 ;s[i]!= '\0'; i++){
            int digit = s[i] - '0';
            if(digit == 0 || digit >= 4) continue;
            int check = ans - digit + digit*digit;
            if(check % 9 == 0 ){
                res [idx++] = 1;
                ok = 0;
                break;
            }
        }
        if(ok) res[idx++] = 0;
    }
    for(int i = 0 ; i < idx ; i++){
        if(res[i]==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void solve() {
    string input;
    cin >> input;
    vector<int> s;
    for (char c : input) {
        s.push_back(c - '0');
    }
    int sm = 0;
    for (int digit : s) {
        sm += digit;
    }
    int twos = count(s.begin(), s.end(), 2);
    int threes = count(s.begin(), s.end(), 3);
    for (int i = 0; i < min(10, twos + 1); i++) {
        for (int j = 0; j < min(10, threes + 1); j++) {
            if ((sm + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define MAX 10000
using namespace std;
unsigned long long SumDigits(char s[]){
    unsigned long long ans = 0 ;
    for(int i = 0 ;s[i]!= '\0'; i++){
        ans += s[i] -'0';
    }
    return ans;
}
int main(){
    int t; cin>>t;
    cin.ignore();
    int idx = 0;
    int res[10000] ;
    while(t--){
        bool ok = 1;
        char s[MAX] ;
        cin.getline(s,10000);
        int ans = SumDigits(s);
        for(int i = 0 ;s[i]!= '\0'; i++){
            int digit = s[i] - '0';
            if(digit == 0 || digit*digit >= 10) continue;
            int check = ans - digit + digit*digit;
            if(check % 9 == 0 ){
                res [idx++] = 1;
                ok = 0;
                break;
            }
        }
        if(ok) res[idx++] = 0;
    }
    for(int i = 0 ; i < idx ; i++){
        if(res[i]==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define MAX 10000
using namespace std;
unsigned long long SumDigits(char s[]){
    unsigned long long ans = 0 ;
    for(int i = 0 ;s[i]!= '\0'; i++){
        ans += s[i] -'0';
    }
    return ans;
}
int main(){
    int t; cin>>t;
    cin.ignore();
    int idx = 0;
    int res[10000] ;
    while(t--){
        bool ok = 1;
        char s[MAX] ;
        cin.getline(s,10000);
        int ans = SumDigits(s);
        for(int i = 0 ;s[i]!= '\0'; i++){
            int digit = s[i] - '0';
            if(digit == 0 || digit*digit >= 10) continue;
            int check = ans - digit + digit*digit;
            if(check % 9 == 0 ){
                res [idx++] = 1;
                ok = 0;
                break;
            }
        }
        if(ok) res[idx++] = 0;
    }
    for(int i = 0 ; i < idx ; i++){
        if(res[i]==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define MAX 10000
using namespace std;
unsigned long long SumDigits(char s[]){
    unsigned long long ans = 0 ;
    for(int i = 0 ;s[i]!= '\0'; i++){
        ans += s[i] -'0';
    }
    return ans;
}
int main(){
    int t; cin>>t;
    cin.ignore();
    int idx = 0;
    int res[10000] ;
    while(t--){
        bool ok = 1;
        char s[MAX] ;
        cin.getline(s,10000);
        int ans = SumDigits(s);
        if (ans % 9 == 0 ) {res[idx++] = 1; ok = 0;}
        for(int i = 0 ;s[i]!= '\0'; i++){
            int digit = s[i] - '0';
            if(digit == 0 || digit >= 4) continue;
            int check = ans - digit + digit*digit;
            if(check % 9 == 0 ){
                res [idx++] = 1;
                ok = 0;
                break;
            }
        }
        if(ok) res[idx++] = 0;
    }
    for(int i = 0 ; i < idx ; i++){
        if(res[i]==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
Problem: 2049C - MEX Cycle
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in ans : ans[y]=0

    elif 1 not in ans : ans[y]=1

    else : ans[y]=2

    print(*ans)
Problem: 2049C - MEX Cycle
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in ans : ans[y]=0

    elif 1 not in ans : ans[y]=1

    else : ans[y]=2

    print(*ans)

Submission (verdict: Runtime error on test 1):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in li : ans[y]=0

    elif 1 not in li : ans[y]=1

    else : li[y]=2

    print(*ans)
Problem: 2049C - MEX Cycle
Language: PyPy 3-64

Previous submission (verdict: Runtime error on test 1):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in li : ans[y]=0

    elif 1 not in li : ans[y]=1

    else : li[y]=2

    print(*ans)

Submission (verdict: Accepted):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in li : ans[y]=0

    elif 1 not in li : ans[y]=1

    else : ans[y]=2

    print(*ans)
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int dp[1001][1001];

int minChange(int aIndex, int bIndex, string &a, string &b, string &c) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    memset(dp, -1, sizeof dp);
    cout << minChange(0, 0, a, b, c) << endl;
  }
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}

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

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

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

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


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

int dp[1001][1001];

int minChange(int aIndex, int bIndex, string &a, string &b, string &c) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(a[aIndex] == c[cIndex])
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c));
  if(b[bIndex] == c[cIndex])
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c));

  // assuming we took from a and it was changed
  mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1);
  // assuming we took from b and it was changed
  mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1);
  
  return dp[aIndex][bIndex] = mn;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    memset(dp, -1, sizeof dp);
    cout << minChange(0, 0, a, b, c) << endl;
  }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

int dp[1001][1001];

int minChange(int aIndex, int bIndex, string &a, string &b, string &c) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(a[aIndex] == c[cIndex])
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c));
  if(b[bIndex] == c[cIndex])
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c));

  // assuming we took from a and it was changed
  mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1);
  // assuming we took from b and it was changed
  mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1);
  
  return dp[aIndex][bIndex] = mn;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    memset(dp, -1, sizeof dp);
    cout << minChange(0, 0, a, b, c) << endl;
  }
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

int dp[1001][1001];

int minChange(int aIndex, int bIndex, string &a, string &b, string &c) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    memset(dp, -1, sizeof dp);
    cout << minChange(0, 0, a, b, c) << endl;
  }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a[i];
    }
    if(n == 1) {
        cout << a[0] << "\n";
        return;
    }
    ll res = -1e18;
    while(n >= 1) {
        ll sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, max(sum, -sum));
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
    }
    cout << res << "\n";
}

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

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

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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = sum;
    while(n > 1) {
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
        sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, abs(sum));
    }
    cout << res << "\n";
}

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

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = sum;
    while(n > 1) {
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
        sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, abs(sum));
    }
    cout << res << "\n";
}

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

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

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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = sum;
    while(n > 1) {
        n--;
        for(int i = 0;i < n;i++) {
            a[i] = a[i + 1] - a[i];
        }
        sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, abs(sum));
    }
    cout << res << "\n";
}

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

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = sum;
    while(n > 1) {
        n--;
        for(int i = 0;i < n;i++) {
            a[i] = a[i + 1] - a[i];
        }
        sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, abs(sum));
    }
    cout << res << "\n";
}

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

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

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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a[i];
    }
    if(n == 1) {
        cout << a[0] << "\n";
        return;
    }
    ll res = -1e18;
    while(n >= 1) {
        ll sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, max(sum, -sum));
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
    }
    cout << res << "\n";
}

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

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a[i];
    }
    if(n == 1) {
        cout << a[0] << "\n";
        return;
    }
    ll res = -1e18;
    while(n >= 1) {
        ll sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, max(sum, -sum));
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
    }
    cout << res << "\n";
}

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

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

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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = sum;
    while(n > 1) {
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
        sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, abs(sum));
    }
    cout << res << "\n";
}

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

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


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

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a[i];
    }
    if(n == 1) {
        cout << a[0] << "\n";
        return;
    }
    ll res = -1e18;
    while(n >= 1) {
        ll sum = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i];
        }
        res = max(res, max(sum, -sum));
        for(int i = 1;i < n;i++) {
            a[i - 1] = a[i] - a[i - 1];
        }
        n--;
    }
    cout << res << "\n";
}

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

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