ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: c++17 

Solution 1 (runtime: 92 ms):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t;

    cin >> t;

    

    while (t--) {

        int n, x, y;

        cin >> n >> x >> y;

        --x;

        --y;



        vector<int> groups(n);



        groups[x] = 0;



        for (int i = (x + 1 + n) % n; i != y; i = (i + 1 + n) % n){

            groups[i] = (groups[(i-1) % n] + 1) % 2;



        }

    

        for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n){

            groups[i] = (groups[(i+1) % n] + 1) % 2;



        }



        if (groups[(y - 1) % n] == 1 || groups[(y+1) % n] == 1) groups[y] = 2;

        else{

            groups[y] = 1;

        }

        for (auto g : groups){

            cout << g << " ";

        }

        cout << '\n';

    }

}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

using namespace std;

#define pi (3.141592653589)

#define mod 1000000007

#define pb push_back

#define is insert

#define mp make_pair

#define ff first

#define ss second

#define all(x) x.begin(), x.end()

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define rfr(n) for(int i=n-1;i>=0;i--)

#define rep1(i,a,b) for(long long i=a;i<=b;i++)

#define fr(n) for(long long i=0;i<n;i++)

#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)

#define rep(i,a,b) for(long long i=a;i<b;i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long int ll;

typedef long double ld;

typedef vector<ll> vi;

#define nl cout << "\n"

#define int long long int

const unsigned int M = 1000000007;

const int  N = 2e5 + 5 ;





signed main(){

fast;

ll t=1;

cin>>t;

while(t--)

{

    int n,x,y;cin >> n >> x >> y;

    vi ans(n);

    x--,y--;

    fr(n) {

       ans[(x + i) % n] = i % 2;

    }

    if((x - y)%2 == 0 || n%2 != 0) ans[x] = 2;



    fr(n) cout << ans[i] << " ";

    nl;

}

return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626433832795
#define M 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

void yes() {
    cout << "YES\n";
}

void no() {
    cout << "NO\n";
}

ll MOD(ll a) {
    ll b = a % M;
    return b >= 0 ? b : b + M;
}

ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b/2);
    t = MOD(t*t);
    if (b%2==1) t = MOD(t*a);
    return t;
}

void solve() {
    set<int> s;
    int n;
    cin>> n;
    vector<int> a(n);
    for (int i = 0; i  <n; i++) {
        cin >> a[i];
        s.insert(a[i]);
    }
    vector<pair<int,int>> ans;
    for (int i = n-1;i >= 0; i--) {
        auto it = s.find(a[i]);

        while (it != s.begin()) {
            it--;
            ans.push_back({a[i],*it});
        }
        while(it != s.end()) {
            if (*it != a[i])
            ans.push_back({*it,a[i]});
            it++;
        }
        s.erase(a[i]);
    }
    //for (int i = 0; i < n-1; i++) {
    
    cout << ans.size() << "\n";
    for (auto i  : ans) {
        cout << i.first << ' ' << i.second << "\n";
    }
}

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

    int t = 1;
    // cin >> t;

    while (t) {
        solve();
        --t;
    }
}


Solution 2 (runtime: 515 ms):
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

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

	vector<vector<int>> ans;


	for (int i = n - 1; i >= 0; i--) {
		vector<vector<int>> same;
		vector<vector<int>> diffs;
		for (int j = i - 1; j >= 0; j--) {
			if (nums[i] > nums[j]) {
				same.push_back({nums[i], nums[j]});
			}
			else {
				diffs.push_back({nums[j], nums[i]});
			}
		}
		sort(same.begin(), same.end());
		reverse(same.begin(), same.end());
		for (int j = same.size() - 1; j >= 0; j--) {
			same.push_back({same[j][1], same[j][0]});
		}
		for (int j = 0; j < same.size(); j++) {
			ans.push_back(same[j]);
		}
		sort(diffs.begin(), diffs.end());
		for (int j = 0; j < diffs.size(); j++) {
			ans.push_back(diffs[j]);
		}
		
	}

	cout << ans.size() << '\n';
	for (auto& arr : ans) {
		cout << arr[0] << " " << arr[1] << '\n';
	}
}


/*

1 2 3

2 1 3
2 3 1
2 1 3
1 2 3
1 3 2
1 2 3





*/
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1296 ms):
#include<bits/stdc++.h>



using namespace std;



int main(){

    int n;

    cin >> n;

    vector<int> cars(n+1); //shows position of car i

    vector<int> cars2(n+1); //shows car at position i

    vector<int> pos(n+1);

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

        cin >> pos[i];

        cars[i]=n-i+1;

        cars2[i]=n-i+1;

    }

    vector<pair<int,int>> moves;

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

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

            moves.push_back({j,i});

        }

    }

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

        int a=pos[i];

        while(cars2[i]!=a){

            moves.push_back({a,cars2[cars[a]-1]});

            int t=cars2[cars[a]-1];

            swap(cars2[cars[a]],cars2[cars[a]-1]);

            cars[a]--;

            cars[t]++;

        }

    }

    cout << moves.size() << endl;

    for(auto a:moves){

        cout << a.first << " " << a.second << endl;

    }



}



Solution 2 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define all(vec) vec.begin(),vec.end()
#define fsort(vec) sort(vec.begin(),vec.end())
#define sz(vec) (int)vec.size()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7;

int32_t main(){
    fast;
    int t=1;
    while(t--){
        int n;cin>>n;
        vi vec(n);
        vector<bool>vis(n+1,false);
        for(auto &i:vec)cin>>i;
        vpii ans;
        for(int i=n-1;i>=0;i--){
            int car = vec[i];
            for(int j=car-1;j>=1;j--){
                if(!vis[j]){
                    ans.pb({car,j});
                }
            }
            for(int j=1;j<car;j++){
                if(!vis[j]){
                    ans.pb({j,car});
                }
            }
            for(int j=car+1;j<=n;j++){
                if(!vis[j]){
                    ans.pb({j,car});
                }
            }
            vis[car] = true;
        }
        cout<<sz(ans)<<endl;
        for(auto it:ans){
            cout<<it.ff<<" "<<it.ss<<endl;
        }
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 2e5 + 5;

int n, m;

int b[9][3];
void init() { rep(i, 0, 8) rep(j, 0, 2) b[i][j] = (i * 2 + j * 6) % 9; }
bool check(int sum, int x, int y) {
  sum %= 9;
  x = min(8, x);
  y = min(2, y);
  if (sum == 0) return true;
  int z = 9 - sum;
  rep(i, 0, x) rep(j, 0, y) {
    if (b[i][j] == z) return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int t;
  cin >> t;
  while (t--) {
    int x = 0, y = 0;
    string s;
    cin >> s;
    int sum = 0;
    for (char c : s) {
      int a = c - '0';
      sum += a;
      if (a == 2)
        x++;
      else if (a == 3)
        y++;
    }
    if (check(sum, x, y))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        string num;
        cin >> num;
        int sum = 0, freq2 = 0, freq3 = 0;
        for(int i = 0; i < num.size(); i++){
            sum += (int)(num[i] - '0');
            if((int)(num[i] - '0') == 2){freq2++;}
            if((int)(num[i] - '0') == 3){freq3++;}
        }
        
        bool flag = false;

        for(int i = 0; i <= freq2; i++){
            for(int j = 0; j <= freq3; j++){
                if((sum + 6*j + 2*i) % 9 == 0){
                    flag = true;
                    goto end;
                }
            }
        }
        
        end:;
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
        
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 217 ms):
#include<iostream>
#include<vector>
#include<set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t!=0){
    int n;
    int l;
    int r;
    cin>>n>>l>>r;
    vector<int>v;
    for(int i = 0;i<n;i++){
        int num;
        cin>>num;
        v.push_back(num);

    }
    vector<int>a1;
    vector<int>a3;
     for(int i = 0;i<n;i++){
      
        if(i>=(l-1)&& i<=(r-1)){
           a3.push_back(v[i]);
           a1.push_back(v[i]);
        }
        if(i<(l-1)){
            a1.push_back(v[i]);
            
        }
        else if(i>(r-1)){
            a3.push_back(v[i]);
        }
     }
     
   
    sort(a1.begin(),a1.end());
    sort(a3.begin(),a3.end());
    long long temp = 0;
    long long temp2 = 0;
    for(int i = 0;i<(r-l+1);i++){
        temp+=a1[i];
    }

    for(int i = 0;i<(r-l+1);i++){
        temp2+=a3[i];
    }

    cout<<min(temp,temp2)<<endl;  


    t--;

    }


    return 0;
}

Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) (a).begin(), (a).end()
#define pb(x) push_back(x)
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define show(a)                        \
    for (int i = 0; i < a.size(); i++) \
        cout << a[i] << " ";           \
    cout << "\n";
#define vec vector<ll>
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define COUNT(x, u) count(all(x), u) // vect strings...

ll MOD = 1000000007;

bool compair(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.first != b.first)
    {
        return b.first > a.first;
    }
    else
    {
        return b.second < b.second;
    }
}
bool isPrime(ll a)
{
    for (ll i = 2; i * i <= a; i++)
    {
        if (a % i == 0)
        {
            return 0;
        }
    }
    return 1;
}
long long binpow(long long a, long long b)

{
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

void solve()
{
    ll n, m, ai, k,l,r;
    cin >> n>>l>>r;
    vec v,v1;
    fr(i,0,n){
        cin>>ai;
        if(i<=r-1){
            v.pb(ai);
        }
        if(i>=l-1){
            v1.pb(ai);
        }
    }
    sort(all(v1));
    sort(all(v));
    ll min1=0,min2=0;
    fr(i,0,r-l+1){min1+=v[i];min2+=v1[i];}
    cout<<min(min1,min2)<<"\n";





}

class first
{
public:
    int x, y;
    first(int x, int y)
    {

        this->x = x;
        this->y = y;
    }

    void print();
};

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

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base::sync_with_stdio(false), cin.tie(NULL));
#define vi              vector<int>
using namespace std;

void solve() {
    int l, r;
    cin >> l >> r;

    if (l == r) {
        cout << "-1\n";
        return;
    }

    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1);
    int b = a + 1;
    int c = (a == l ? r : l);

    cout << a << " " << b << " " << c << "\n";
}

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


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int inf = 1e18, mod = 998244353;

void solve()
{
	int l, r;
    cin >> l >> r;
    int a = 0, b = 0;
    for (int i = 29; i >= 0; i -- )
    {
        if ((l ^ r) >> i & 1) 
        {
            a |= (1 << i) - 1;
            b |= 1 << i;
            break;
        }
        else
        {
            a |= l & (1 << i);
            b |= l & (1 << i);
        }
    }
    int c = l;
    while (c == a || c == b)
    {
        c ++ ;
    }
    cout << a << ' ' << b << ' ' << c << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int T = 1;
	cin >> T;
	while (T -- )
	{
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;


const int N = 1e3 + 5;

char a[N], b[N], c[N * 2];
int n, m, id;
int vis[N][N], mem[N][N];

int solve(int i, int j){
	if(vis[i][j] == id){
		return mem[i][j];
	}
	vis[i][j] = id;
	if(i >= n){
		int tmp = 0;
		while(j < m){
			tmp += b[j] != c[i + j];
			++j;
		}
		return tmp;
	}
	if(j >= m){
		int tmp = 0;
		while(i < n){
			tmp += a[i] != c[i + j];
			++i;
		}
		return tmp;
	}
	int ret = 1e9;
	ret = min(ret, solve(i + 1, j) + (a[i] != c[i + j]));
	ret = min(ret, solve(i, j + 1) + (b[j] != c[i + j]));
	return mem[i][j] = ret;
}
int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		++id;
		scanf(" %s", a);	
		scanf(" %s", b);
		scanf(" %s", c);
		n = strlen(a);
		m = strlen(b);
		printf("%d\n", solve(0, 0));
	}
	return 0;
}

Solution 2 (runtime: 92 ms):
#include<bits/stdc++.h>
using namespace std;
#define uo cout<<u<<endl;
#define vi vector<int> 
#define pi cin>>p;
#define pqi cin>>p>>q;
#define pqri cin>>p>>q>>r;
#define rep(i,j,p) for(i=0;i<p;i++)
#define st string s
int loop(long long int k,int a[],int b[],int p,long long int u,int q)
{
   long long int o,e,i,j;
   o=0;
   e=0;
   for(i=0;i<q;i++)
   {
     if(b[i]==1)
     {
       e+=a[i]*k;
     }
     else
     {
       o=k/b[i];
       e+=(o*a[i]);
       o=k%b[i];
       if(o!=0)
       e+=a[i];
     }
     if(e>=p)
     return 1;
   }
   return 0;
}
int gcd(long long int u,long long int v)
{
  if(v==0) return u;
  return gcd(v,u%v);
}
int find(vector<string> &v,vector<vector<int>> &dp,int p,int q,int i,int j,int l)
{
   int u,k;
   u=0;
   if(i>=p || j>=q || i<0 || j<0)
   {
    return 0;
   }
   if(dp[i][j]!=-1)
   {
    return dp[i][j];
   }
   if(v[i][j]=='?')
   {
    dp[i][j]=1;
    return 2;
   }
   dp[i][j]=1;
   if(v[i][j]=='D')
   u+=find(v,dp,p,q,i+1,j,l);
   if(v[i][j]=='L')
   u+=find(v,dp,p,q,i,j-1,l);
   if(v[i][j]=='U')
   u+=find(v,dp,p,q,i-1,j,l);
   if(v[i][j]=='R')
   u+=find(v,dp,p,q,i,j+1,l);
   if(u!=0)
   {
   dp[i][j]=1;
   u++;
   }
   else
   {
   dp[i][j]=0;
   }
   return u;
}
int loop1(string &s,string &l,string &n,vector<vector<int>> &dp,int w,int m,int e)
{
  int p,q,r,k,u,v,i,j;
  p=s.size();
  q=l.size();
  u=1e9;
  v=1e9;
  if(e==(p+q))
  {
    return 0;
  }
  if(dp[w][m]!=-1)
  {
    return dp[w][m];
  }
  if(w!=p && s[w]==n[e])
  {
    u=loop1(s,l,n,dp,w+1,m,e+1);
  }
  else if(w!=p)
  {
    u=1+loop1(s,l,n,dp,w+1,m,e+1);
  }
  if(m!=q && l[m]==n[e])
  {
    v=loop1(s,l,n,dp,w,m+1,e+1);
  }
  else if(m!=q)
  {
    v=1+loop1(s,l,n,dp,w,m+1,e+1);
  }
  u=min(u,v);
  dp[w][m]=u;
  return u;
}
int main ()
{
  int t;
  cin>>t;
  while(t--)
  {
    int p,q,r,k,u,v,i,j;
    string s;
    string l;
    string n;
    cin>>s>>l>>n;
    p=s.size();
    q=l.size();
    vector<vector<int>> dp(p+2,vector<int>(q+2,-1));
    u=loop1(s,l,n,dp,0,0,0);
    cout<<u<<endl;
 }
  return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 311 ms):
#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for(auto &it : arr){
            cin >> it;
        }
        
        long long sum_odd = 0, sum_even = 0;
        int n_odd = (n%2 == 0)? n/2 : n/2 + 1, n_even = n/2;
        
        for(int i = 0; i < n; i += 2){
            sum_odd += arr[i];
        }
        for(int j = 1; j < n; j += 2){
            sum_even += arr[j];
        }
        
        if(sum_odd % n_odd == 0 && sum_even % n_even == 0 && (sum_odd/n_odd) == (sum_even/n_even)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Solution 2 (runtime: 328 ms):
// Problem: B. Transfusion

// Contest: Codeforces - Codeforces Round 991 (Div. 3)

// URL: https://codeforces.com/contest/2050/problem/B

// Memory Limit: 256 MB

// Time Limit: 2000 ms

// 

// Powered by CP Editor (https://cpeditor.org)



//#pragma GCC optimize("O3")

//#pragma GCC optimize("Ofast")



#include <bits/stdc++.h>

#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define pii pair<int, int>

#define pdd pair<double, double>

#define lowbit(x) (x & -x)

#define all(x) x.begin(), x.end()



#define Rep(i, x) for(auto &i : x)

#define L(i, x, y) for(int i = x; i <= y; ++ i)

#define R(i, x, y) for(int i = x; i >= y; -- i)

#define rd(x) scanf("%lld", &(x))

#define p_b push_back

#define ft first

#define sd second

using namespace std;

template <class T> using vc = vector<T>;

template <class T> using _pq = priority_queue<T, vector<T>, greater<T>>;

using i64 = long long;

using u64 = unsigned long long;

using u32 = unsigned;

const int N = 2e5 + 10;





































































void solve() {

	int n; cin >> n;

	vc<int> a(n);

	L(i, 0, n - 1) cin >> a[i];

	i64 sum = reduce(a.begin(), a.end());

	if(sum % n) {

		cout << "NO\n";

		return;

	}

	int sd = sum / n;

	//cout << sd << "\n";

	L(i, 0, n - 1) {

		//cout << i << " " << a[i] << "\n";

		if(i >= n - 2 && a[i] != sd) {

			cout << "NO\n";

			return;

		}

		if(a[i] == sd) continue;

		else {

			if((a[i] + a[i + 2]) / 2 != sd || (a[i] + a[i + 2]) % 2) {

				if(a[i] < sd) {

					int dif = sd - a[i];

					a[i] = sd;

					if(a[i + 2] >= dif) a[i + 2] -= dif;

					else {

						cout << "NO\n";

						return;

					}

				}

				else {

					int dif = a[i] - sd;

					a[i] = sd;

					a[i + 2] += dif;

				}

				

			}

			else {

				a[i] = (a[i] + a[i + 2]) / 2;

				a[i + 2] = a[i];

			}

			

		}

	}

	//L()

	cout << "YES\n";

}





int main() {

	Begin;

	int _; _ = 1;

	cin >> _;

	while(_--) solve();

	return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define space " "
#define mod 1000000007
#define pb push_back
#define all(v) (v.begin(), v.end())
#define allr(v) (v.begin(), v.end(),greater<>())
#define pyes cout<<"YES"<<"\n";
#define pno cout<<"NO"<<"\n";
#define sortv sort(v.begin(),v.end())
#define sortvg sort(v.begin(),v.end(),greater<>())
#define ll long long
#define forl(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define setprecision(x) cout << fixed << setprecision(x)



void mine(){
    ll n; cin>>n;

    vector<ll>v(n);

    forl(i,n)cin>>v[i];

    ll sum=0;

    forl(i,n)sum+=v[i];

    ll res=sum;

    ll nn=n-1;

    for(ll i=1; i<n; i++){

        sum=0;

        forl(i,nn)v[i]=v[i+1]-v[i];

        forl(i,nn)sum+=v[i];

        res=max(res,max(sum,-sum));

        nn--;
    }

    cout<<res<<endl;
    
};

int main()
{
    int t=1; 
    cin>>t;
    
    while(t--){
        mine();
    }

    return 0;
}

Solution 2 (runtime: 61 ms):
#define SETBIT(x, i) ((x & (1 << i)) != 0)
#define ll long long
#include<bits/stdc++.h>
#define inf LLONG_MAX
#define neg_inf LLONG_MIN
using namespace std ;
void solve(){
  int n ;
  cin>>n ;
  vector<ll>arr(n) ;
  int cntneg=0 ;
  for(int i=0 ; i<n ; i++){
    cin>>arr[i] ;
    if(arr[i]<0)cntneg++;
}
  if(n==1){
    cout<<arr[0]<<endl;
    return ;
  }
  
  ll ans =0 ;
  for(int i=0 ; i<n ; i++)ans+=arr[i] ;
   
  vector<ll>temp = arr ;
  for(int i=0 ; i<n-1 ; i++){
    vector<ll> k ;
     for(int j=1 ; j<temp.size() ; j++){
      k.push_back(temp[j]-temp[j-1]);
    }
    temp = k ;
 
    ll S = 0 ;
    for(int i=0 ; i<k.size();i++)S+=k[i] ;
    ans = max(ans , S) ;
  ans = max(ans,-S) ;
  }
  cout<<ans<<endl;

}
int main(){
  ll t ;
  cin>>t ;
  while(t--)solve() ;
  return 0 ;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std ;


int main(){
   int t ;
   cin >> t ;
   while(t--)
   {
        int n ;
        cin >> n ;
        vector<long long> arr(n);
        for(int i = 0 ; i < n ; i++ ){
             cin >> arr[i] ;
        }
        long long ans = -1e18;
        int now  = n ;
        for(int i = 0 ; i  < n  ; i++ ){
                long long sum = 0 ;
                 for(int j = 0 ; j < now ; j++ ) sum += arr[j] ;
                 if(i == 0 ) ans = max(sum , ans );
                 else ans = max({ans , sum , (-sum )});
                 for(int j = 0 ; j < now  - 1   ; j++ ) arr[j] = arr[j+1 ] - arr[j] ;
                 now--;
        } 
        cout << ans<< endl;

   }





return 0 ;
}

Solution 2 (runtime: 46 ms):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


long long nChoosek( long long n, long long k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    long long result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


//long long power(long long a, long long b, long long m){
//    if (b==0) return 1;
//    if (b==1) return a%m;
//    
//    long long temp=power(a,b/2,m)%m;
//    if (b%2) return (temp*temp*a)%m;
//    else return (temp*temp)%m;
//}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        vector<long long> diffs;
        for (int i=1; i<=n-1; i++){
            for (int i=0; i<nos.size()-1; i++){
                long long x=nos[i]-nos[i+1];
                ans2+=x;
                diffs.push_back(x);
            }
            nos=diffs;
            diffs.clear();
//            cout<<nos.size()<<"size"<<diffs.size()<<endl;

            if (abs(ans2)>ans1) ans1=abs(ans2);
            ans2=0;
        }
        
        cout<<ans1<<endl;
    }
}