ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

const int N = 55;
int a[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll ans = 0;
	while (n > 1) {
		ll res = 0;
		for (int i = 1; i <= n; ++i) {
			res += a[i];
		}
		ans = max(res, ans);
		res = 0;
		for (int i = 1; i < n; ++i) {
			a[i] = a[i + 1] - a[i];
			res += a[i];
		}
		ans = max(abs(res), ans);
		n--;
	}
	cout << ans << endl;
	return;
}

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

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

const int N = 55;
int a[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll ans = 0;
	if (n == 1) {
		cout << a[1] << endl;
		return;
	}
	while (n > 1) {
		ll res = 0;
		for (int i = 1; i <= n; ++i) {
			res += a[i];
		}
		ans = max(res, ans);
		res = 0;
		for (int i = 1; i < n; ++i) {
			a[i] = a[i + 1] - a[i];
			res += a[i];
		}
		ans = max(abs(res), ans);
		n--;
	}
	cout << ans << endl;
	return;
}

int main() {
	int t;
	cin >> t;
	while (t--)solve();
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 1):
#include<iostream>
#include<vector>
using namespace std;
string answer(vector<int>nums){
    for(int i=0;i<nums.size()-1;i++){
        int minimum=min(nums[i],nums[i+1]);
        nums[i]-=minimum;
        nums[i+1]-=minimum;
        if(nums[i]>nums[i+1]) return "NO";
    }
    return "YES";
}
int main(){
    int t;
    cin>>t;
    while(t--){
    vector<int>nums;
    int n;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        nums.push_back(val);
    }
    cout<<answer(nums)<<endl;
}        
return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
using namespace std;
string answer(vector<int>nums){
    for(int i=0;i<nums.size()-1;i++){
        int minimum=min(nums[i],nums[i+1]);
        nums[i]-=minimum;
        nums[i+1]-=minimum;
        if(nums[i]>nums[i+1]) return "NO";
    }
    return "YES";
}
int main(){
    int t;
    cin>>t;
    while(t--){
    vector<int>nums;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        nums.push_back(val);
    }
    cout<<answer(nums)<<endl;
}        
return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<vector>
using namespace std;
string answer(vector<int>nums){
    for(int i=0;i<nums.size()-1;i++){
        int minimum=min(nums[i],nums[i+1]);
        nums[i]-=minimum;
        nums[i+1]-=minimum;
        if(nums[i]>nums[i+1]) return "NO";
    }
    return "YES";
}
int main(){
    int t;
    while(t--){
    vector<int>nums;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        nums.push_back(val);
    }
    cout<<answer(nums)<<endl;
}        
return 0;
}

Submission (verdict: Runtime error on test 1):
#include<iostream>
#include<vector>
using namespace std;
string answer(vector<int>nums){
    for(int i=0;i<nums.size()-1;i++){
        int minimum=min(nums[i],nums[i+1]);
        nums[i]-=minimum;
        nums[i+1]-=minimum;
        if(nums[i]>nums[i+1]) return "NO";
    }
    return "YES";
}
int main(){
    int t;
    cin>>t;
    while(t--){
    vector<int>nums;
    int n;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        nums.push_back(val);
    }
    cout<<answer(nums)<<endl;
}        
return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<vector>
using namespace std;
string answer(vector<int>nums){
    for(int i=0;i<nums.size()-1;i++){
        int minimum=min(nums[i],nums[i+1]);
        nums[i]-=minimum;
        nums[i+1]-=minimum;
        if(nums[i]>nums[i+1]) return "NO";
    }
    return "YES";
}
int main(){
    int t;
    while(t--){
    vector<int>nums;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        nums.push_back(val);
    }
    cout<<answer(nums)<<endl;
}        
return 0;
}
Problem: 2061D - Kevin and Numbers
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}


Submission (verdict: Accepted):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (Objects.equals(pq1.peek(), pq2.peek())){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}
Problem: 2061D - Kevin and Numbers
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Integer> pq1 = new PriorityQueue<>((o1, o2) -> o2 - o1);
    PriorityQueue<Integer> pq2 = new PriorityQueue<>((o1, o2) -> o2 - o1);
    for (int x : a) pq1.offer(x);
    for (int x : b) pq2.offer(x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        int x = pq2.poll();
        int x1 = x / 2;
        int x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}


Submission (verdict: Wrong answer on test 1):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      System.out.println(Objects.equals(pq1.peek(), pq2.peek()));
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}
Problem: 2061D - Kevin and Numbers
Language: Java 21

Previous submission (verdict: Wrong answer on test 1):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      System.out.println(Objects.equals(pq1.peek(), pq2.peek()));
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}


Submission (verdict: Wrong answer on test 2):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}
Problem: 2061D - Kevin and Numbers
Language: Java 21


Submission (verdict: Wrong answer on test 2):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Integer> pq1 = new PriorityQueue<>((o1, o2) -> o2 - o1);
    PriorityQueue<Integer> pq2 = new PriorityQueue<>((o1, o2) -> o2 - o1);
    for (int x : a) pq1.offer(x);
    for (int x : b) pq2.offer(x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (pq1.peek() == pq2.peek()){
        pq1.poll();
        pq2.poll();
      }
      else {
        int x = pq2.poll();
        int x1 = x / 2;
        int x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3

Previous submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    print(b | k, b | k - 1, b | k +1)

Submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    print(b | k, (b | k) - 1, (b | k) +1)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3

Previous submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    print(b | k, b | k, a & (~k))

Submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    print(b | k, b | k - 1, b | k +1)
Problem: 2057C - Trip to the Olympiad
Language: PyPy 3

Previous submission (verdict: Wrong answer on test 1):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    print(b | k, (b | k) - 1, (b | k) +1)

Submission (verdict: Accepted):
for _ in range(int(input())):
    b, a = map(int, input().split())
    k = (1 << ((a^b).bit_length()-1)) - 1
    if (b|k == b):
        m = (b|k)+2
    else:
        m = (b | k) -1
    print(b | k, m, (b | k) +1)
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll N = 2e6 + 10;
ll n, m, k, q;
ll sum = 0;
ll a[N], b[N];
vector<ll> p[N];
ll c[51][51];
void inti()
{
	c[1][1] = 1;
	c[1][0] = 1;
	for (ll i = 2; i <= 50; i++)
	{
		c[i][i] = c[i][0] = 1;
		for (ll j = 1; j < i; j++)
		{
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}
void solve()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ans += a[i];
	}
	for (ll i = 1; i < n; i++)
	{
		ll sum1 = 0, sum2 = 0;
		ll f = 1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = 1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, -sum1));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
			ans = max(ans, sum1 - sum2);
		}
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll t = 1;
	inti();
	cin >> t;
	while (t--)
		solve();
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll N = 2e6 + 10;
ll n, m, k, q;
ll sum = 0;
ll a[N], b[N];
vector<ll> p[N];
ll c[51][51];
void inti()
{
	c[1][1] = 1;
	c[1][0] = 1;
	for (ll i = 2; i <= 50; i++)
	{
		c[i][i] = c[i][0] = 1;
		for (ll j = 1; j < i; j++)
		{
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}
void solve()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ans += a[i];
	}
	for (ll i = 1; i < n; i++)
	{
		ll sum1 = 0, sum2 = 0;
		ll f = 1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = 1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, sum2));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
		}
		sum1 = 0, sum2 = 0;
		f = -1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = -1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, sum2));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
		}
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll t = 1;
	inti();
	cin >> t;
	while (t--)
		solve();
	return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll N = 2e6 + 10;
ll n, m, k, q;
ll sum = 0;
ll a[N], b[N];
vector<ll> p[N];
ll c[51][51];
void inti()
{
	c[1][1] = 1;
	c[1][0] = 1;
	for (ll i = 2; i <= 50; i++)
	{
		c[i][i] = c[i][0] = 1;
		for (ll j = 1; j < i; j++)
		{
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}
void solve()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ans += a[i];
	}
	for (ll i = 1; i < n; i++)
	{
		ll sum = 0;
		for (ll j = n; j > i; j--)
		{
			a[j] = a[j] - a[j - 1];
			sum += a[j];
		}
		ans = max(ans, abs(sum));
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll t = 1;
	inti();
	cin >> t;
	while (t--)
		solve();
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll N = 2e6 + 10;
ll n, m, k, q;
ll sum = 0;
ll a[N], b[N];
vector<ll> p[N];
ll c[51][51];
void inti()
{
	c[1][1] = 1;
	c[1][0] = 1;
	for (ll i = 2; i <= 50; i++)
	{
		c[i][i] = c[i][0] = 1;
		for (ll j = 1; j < i; j++)
		{
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}
void solve()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ans += a[i];
	}
	for (ll i = 1; i < n; i++)
	{
		ll sum1 = 0, sum2 = 0;
		ll f = 1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = 1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, -sum1));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
			ans = max(ans, sum1 - sum2);
		}
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll t = 1;
	inti();
	cin >> t;
	while (t--)
		solve();
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll N = 2e6 + 10;
ll n, m, k, q;
ll sum = 0;
ll a[N], b[N];
vector<ll> p[N];
ll c[51][51];
void inti()
{
	c[1][1] = 1;
	c[1][0] = 1;
	for (ll i = 2; i <= 50; i++)
	{
		c[i][i] = c[i][0] = 1;
		for (ll j = 1; j < i; j++)
		{
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}
void solve()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ans += a[i];
	}
	for (ll i = 1; i < n; i++)
	{
		ll sum1 = 0, sum2 = 0;
		ll f = 1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = 1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, sum2));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
		}
		sum1 = 0, sum2 = 0;
		f = -1;
		for (ll j = 1; j <= i + 1; j++)
		{
			sum1 += f * c[i][j - 1] * a[j];
			f *= -1;
		}
		f = -1;
		for (ll j = n; j >= n - i; j--)
		{
			sum2 += f * c[i][n - j] * a[j];
			f *= -1;
		}
		if (i == n - 1)
		{
			ans = max(ans, max(sum1, sum2));
		}
		else
		{
			ans = max(ans, sum2 - sum1);
		}
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll t = 1;
	inti();
	cin >> t;
	while (t--)
		solve();
	return 0;
}