ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 78 ms):
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <vector>
#include <set>
#include <algorithm>
#include <array>
#include <functional>
#include <deque>

#include <cassert>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <locale>
#include <memory>
#include <stdexcept>
//#include <ranges>

using namespace std;

typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int, int> ii;

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

#ifdef HIEPDANG
#define REDIRECT freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL);
#else
#define REDIRECT ;
#endif

int dx[] = { 0, 1,  0, 1,  1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0,  1, -1, 1, -1 };


void solve() {
   string s;
   cin >> s;

   
   for (int i = 0; i < s.size(); i++) {
      int best = 0;
      int pos = -1;

      for (int j = 1; j < 10 && (j + i) < s.size(); j++) {
         int consider = (s[i + j] - '0' - j) - (s[i] - '0');
         if (consider > best) {
            best = consider;
            pos = i + j;
         }
      }

      if (pos > -1) {
         s[pos] -= (pos - i);
      }

      for (int p = pos; p > i; p--) {
         swap(s[p], s[p - 1]);
      }
   }

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

int main()
{
   REDIRECT;
   int tc = 1;
   cin >> tc;

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

   return 0;
}



Solution 2 (runtime: 77 ms):
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

bool should_swap(string& s, int i) {
  return s[i]-'0' >= 1 && s[i]-'0' > s[i-1]-'0'+1;
}

void do_swap(string& s, int j) {
  char tmp = s[j-1];
  s[j-1] = '0'+(s[j]-'0'-1);
  s[j] = tmp;
}

int main() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 1; j < s.size(); j++) {
      if (should_swap(s, j)) {
        do_swap(s, j);
        for (int k = j-1; k >= 1; k--) {
          if (should_swap(s, k)) do_swap(s, k);
          else break;
        }
      }
    }
    cout << s << endl;
  }

  return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[200005];
ll gcd(ll a,ll b){
	if(a%b==0){
		return b;
	}
	return gcd(b,a%b);
}
int main(int argc, char** argv) {
	cin>>n;
	while(n-->0){
		int x;
		cin>>x;
		ll sum=0;
		for(int i=0;i<x;i++){
			cin>>a[i];
			sum+=a[i];
		}
		if(sum%x==0){
			ll sum1=0;
			ll sum2=0;
			for(int i=0;i<x;i+=2){
				sum1+=a[i];
			}
			for(int i=1;i<x;i+=2){
				sum2+=a[i];
			}
			if(sum1>=sum2){
				ll c=gcd(sum1,sum2);
				if(x%2==1){
					if(sum1%(x/2+1)==0){
						if(sum1==sum2+c){
							cout<<"YES"<<endl;
						}else{
							cout<<"NO"<<endl;
						}
					}else{
						cout<<"NO"<<endl;
					}
				}else{
					if(sum1==sum2&&sum1%(x/2)==0){
						cout<<"YES"<<endl;
					}else{
						cout<<"NO"<<endl;
					}
				} 
				
			}else{
				cout<<"NO"<<endl;
			}
		}else{
			cout<<"NO"<<endl;
		}
	}
}

Solution 2 (runtime: 93 ms):
/*
Author: Yeasin Arafat
Source:
*/

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--)
    {
        long long n;
        cin >> n;
        long long sum = 0;
        // vector<int> v(n);
        long long v[n+10];
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
            sum += v[i];
        }
        // cout<<sum<<endl;
        if (sum % n == 0)
        {
            long long need = sum / n, f = 0;
            for (int i = 1; i <= n - 1; i++)
            {
                if (v[i - 1] != need)
                {
                    if (v[i - 1] < need)
                    {
                        long long lagbe = need - v[i - 1];
                        v[i - 1] = need;
                        v[i + 1] -= lagbe;
                    }
                    else
                    {
                        long long lagbe = v[i - 1] - need;
                        v[i - 1] = need;
                        v[i + 1] += lagbe;
                    }
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (v[i] != need)
                {
                    f = 1;
                    break;
                }
            }
         if(f)cout<<"NO"<<endl;
         else cout<<"YES"<<endl;
        }
    
        else
            cout << "NO" << endl;
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 906 ms):
#include<iostream>
#include<vector>
#include<set>
using namespace std;
const int maxn = 2 * 100000 + 10;
vector<int> v[maxn];

void solve()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++) v[i].clear();
	
	for(int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	int ans = 0;
	
	for(int i = 1; i <= n; i++){
		for(auto x : v[i]){
			ans = max(ans, (int)(v[i].size() + v[x].size() - 2));
		}
	}
	
	multiset<int, greater<int> > s;
	
	for(int i = 1; i <= n; i++){
		s.insert(v[i].size());
	}
	
	for(int i = 1; i <= n; i++){
		s.erase(s.find(v[i].size()));
		
		for(auto x : v[i]){
			s.erase(s.find(v[x].size()));
		}
		
		ans = ans = max(ans, (int)(v[i].size() + (int)*s.begin() - 1));
		
		s.insert(v[i].size());
		
		for(auto x : v[i]){
			s.insert(v[x].size());
		}
	}
	
	cout << ans << endl;
}

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

Solution 2 (runtime: 468 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<vector<int>> G;
vector<unordered_set<int>> neigh;
vector<int> degs;
vector<int> ids;

pii findBest(){
    for(int i = 0 ; i < ids.size() ; i++){
        for(int j = i + 1 ; j < ids.size() ; j++){
            if(neigh[ids[i]].count(ids[j]) == 0) return {ids[i], ids[j]};
        } 
    }
    return {-1, -1};
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, t, u, v;
    cin >> t;
    while(t--){
        cin >> n;
        G.clear();
        G.resize(n + 2);
        neigh.clear();
        neigh.resize(n + 2);
        ids.clear();
        degs.clear();
        degs.resize(n + 2);
        for(int i = 1 ; i < n ; i++){
            cin >> v >> u;
            G[u].push_back(v);
            G[v].push_back(u);
            neigh[u].insert(v);
            neigh[v].insert(u);
            degs[u]++;
            degs[v]++;
        }
        int ans = 0, maxDeg = -1, idx = 0;
        pii XD;
        for(int i = 1 ; i <= n ; i++){
            //cerr << degs[i] << " ";
            if(degs[i] > maxDeg){
                ids.clear();
                maxDeg = degs[i];
            }
            if(degs[i] == maxDeg){
                ids.push_back(i);
            }
        }
        idx = ids[0];
        if(ids.size() >= 3){
            XD = findBest();
            cout << degs[XD.first] + degs[XD.second] - 1 << '\n';
        }else{
            ans += maxDeg;
            for(int i : G[idx]){
                degs[i]--;
            }
            degs[idx] = -1;
            maxDeg = -1;
            for(int i = 1 ; i <= n ; i++){
                //cerr << degs[i] << " ";
                if(degs[i] > maxDeg){
                    maxDeg = degs[i];
                    idx = i;
                }
            }
            ans += maxDeg - 1;
            cout << ans << '\n';
        }
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define csb_int __builtin_popcount
#define csb_ll __builtin_popcountll
#define all(x) x.begin(),x.end()
ll f(ll i,ll j,string&a,string&b,string&c,vector<vector<ll>>&dp){
    if(i+j==c.size()-1)return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    ll op=c.size();
    if(i+1 < a.size()){
        if(a[i+1]==c[i+1+j]){
            op=min(op,f(i+1,j,a,b,c,dp));
        }
        if(a[i+1]!=c[i+1+j]){
            op=min(op,1+f(i+1,j,a,b,c,dp));
        }
    }
    if(j+1 < b.size()){
        if(b[j+1]==c[i+j+1]){
            op=min(op,f(i,j+1,a,b,c,dp));
        }
        if(b[j+1]!=c[i+j+1]){
            op=min(op,1+f(i,j+1,a,b,c,dp));
        }
    }
    return dp[i][j]=op;
}
void ans(){
    string a,b,c; 
    cin>>a>>b>>c;
    string a1=" ";
    a1+=a;
    string b1=" ";
    b1+=b;
    string c1=" ";
    c1+=c;
    ll n=a1.size(),m=b1.size();
    vector<vector<ll>>dp(n,vector<ll>(m,-1));
    cout<<f(0,0,a1,b1,c1,dp)<<endl;
}
int main(){
int t;
cin>>t;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);cout.tie(NULL);
while(t--){
ans();
}
return 0;
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define loop(n) for (int i = 0; i < n; i++)
#define fr(i,m,n) for(int i = m; i < n; i++)
#define in cin>>
#define out cout<<
#define pb push_back
#define pp pop_back()
#define ll long long int
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl

string a, b, c;
int func(int ind, int i,int j,int n,int m,vector<vector<int>>& dp){
    if(ind==n+m) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    int x = INT_MAX;
    int y = INT_MAX;
    if(i<n) x = (a[i]!=c[ind])+func(ind+1,i+1,j,n,m,dp);
    if(j<m) y = (b[j]!=c[ind])+func(ind+1,i,j+1,n,m,dp);
    return dp[i][j] = min(x,y);
}

int main(){
    int t;
    in t;
    while(t--){
        in a>>b>>c;
        int n = a.size();
        int m = b.size();
        vector<vector<int>> dp(n+1,vector<int>(m+1,-1));
        out func(0,0,0,n,m,dp)<<endl;

    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

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

vector<vector<int>> dp;

int solve(string &a, string &b, string &c, int i, int j, int na, int nb) {
    if (i == na && j == nb) {
        return 0;
    }

    if (dp[i][j] != -1) return dp[i][j];
    int pos = i + j;
    int res = 1e9;

    if (i < na) {
        int cost = solve(a, b, c, i + 1, j, na, nb) + (a[i] != c[pos]);
        res = min(res, cost);
    }

    if (j < nb) {
        int cost = solve(a, b, c, i, j + 1, na, nb) + (b[j] != c[pos]);
        res = min(res, cost);
    }

    return dp[i][j] = res;
}

int main() {
    int t;
    cin >> t;

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

        int na = a.length(), nb = b.length();
        dp.assign(na + 1, vector<int>(nb + 1, -1));  

        int y = solve(a, b, c, 0, 0, na, nb);
        cout << y << "\n";
    }

    return 0;
}


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

#define int long long

void solve() {
	string a, b, c; cin >> a >> b >> c;
	int n = a.size(); int m = b.size();

	vector<vector<int>> dp(n+1, vector<int>(m+1, 1e9));
	dp[0][0] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i < n) {
				int changeA = (a[i] != c[i+j]);
				dp[i+1][j] = min(dp[i+1][j], dp[i][j] + changeA);
			} 

			if (j < m) {
				int changeB = (b[j] != c[i+j]);
				dp[i][j+1] = min(dp[i][j+1], dp[i][j] + changeB);
			}
		}
	}

	cout << dp[n][m] << endl;
}

signed main() {
	int t; cin >> t;

	while (t--) {
		solve();
	}
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

int main() 
{
    int t;
    cin>>t;
    for(int m=0;m<t;m++)
    {
      
      string s;
      cin>>s;
      for(int i=0;i<s.size();i++)
      { 
        int max_index=i;
        int d=s[i]-'0';
        int e=s.size();
        int q=min(e,i+10);
        for(int j=i+1;j<q;j++)
        {
          int x=(s[j]-'0')-(j-i);
           if(x>d)
           {
             max_index=j;
             d=x;
           }
        }
        
        while(max_index>i)
        {
          swap(s[max_index],s[max_index-1]);
          max_index--;
        }
        s[i]=d+'0';
        
        
        
      }
      
      cout<<s<<endl;
      
      
      
      
    }
    return 0;
}

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

using namespace std;

#define ll long long

#define pb push_back

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

#define INF (ll)1e18

#define vii vector<int>

void solved()

{

    string digit;

    cin >> digit;

    for(int i=1; i<digit.size(); i++)

    {

        int copy = i;

        while(copy > 0 && digit[copy]-1 > digit[copy-1])

        {

            

            digit[copy]--;

            swap(digit[copy],digit[copy-1]);

            copy--;

        }

    }

    cout << digit << endl;

};

int main()

{

    ios_base::sync_with_stdio(false), cin.tie(0);

    ll t;

    cin >> t;

    while(t--)

    {

        solved();

    };

    return 0;

}

//Do it for yourself
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<iostream>
#include<vector>
const int inf = 1e9;
using namespace std;
void solve()
{
	string a, b, c;
	cin >> a >> b >> c;
	int n = (int)a.size(), m = (int)b.size();
	vector<vector<int>> dp(n+1, vector<int> (m+1,inf));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++)
	{
		dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
	}
	for (int j = 0; j < m; j++)
	{
		dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i +j- 1]), dp[i][j - 1] + (b[j - 1] != c[j+i - 1]));
		}
	}
	cout << dp[n][m] << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 140 ms):
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
char a[1010],b[1010],c[2010];
int la,lb,f[1010][1010];
void solve(){
    memset(f,-1,sizeof(f));
    f[0][0]=0;
    la=strlen(a);
    lb=strlen(b);
    for(int i=0;i<=la;i++)
    for(int j=0;j<=lb;j++){
        if(i+1<=la){
            f[i+1][j]=max(f[i+1][j],f[i][j]+(a[i]==c[i+j]?1:0));
        }
        if(j+1<=lb)
            f[i][j+1]=max(f[i][j+1],f[i][j]+(b[j]==c[i+j]?1:0));
    }
    printf("%d\n",la+lb-f[la][lb]);
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",a);
        scanf("%s",b);
        scanf("%s",c);
        solve();
    }
}

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long,long long>>
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair

int diff(string &a, string &c, int i, int k) {
    int counter = 0;
    for (int j = k; j < c.size(); j++) {
        if (c[j] != a[i++]) counter++;
    }
    return counter;
}

int fns(int i, int j, int k, vector<vector<int>> &dp, string &a, string &b, string &c) {
    if (k >= c.size()) return 0;
    //if (i >= a.size() && j >= b.size()) return c.size() - k; // Remaining unmatched characters in `c`
    if (dp[i][j] != -1) return dp[i][j];

    if (i >= a.size()) return dp[i][j] = diff(b, c, j, k);
    if (j >= b.size()) return dp[i][j] = diff(a, c, i, k);

    if (a[i] == c[k] && b[j] == c[k]) {
        return dp[i][j] = min(fns(i + 1, j, k + 1, dp, a, b, c),
                                 fns(i, j + 1, k + 1, dp, a, b, c));
    }
    if (a[i] != c[k] && b[j] != c[k]) {
        return dp[i][j] = 1 + min(fns(i + 1, j, k + 1, dp, a, b, c),
                                     fns(i, j + 1, k + 1, dp, a, b, c));
    }
    if (a[i] == c[k]) {
        return dp[i][j] = min(fns(i + 1, j, k + 1, dp, a, b, c),1+fns(i,j+1,k+1,dp,a,b,c));
    }
    if (b[j] == c[k]) {
        return dp[i][j] =min(fns(i, j + 1, k + 1, dp, a, b, c),1+fns(i+1,j,k+1,dp,a,b,c));
    }
    return 0; // Default case
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    int n1 = a.size(), n2 = b.size(), n3 = c.size();
    vector<vector<int>> dp(n1 + 1, vector<int>(n2 + 1,-1));
    int ans = fns(0, 0, 0, dp, a, b, c);
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 749 ms):
#include<iostream>
#include<cstring>
#define int long long
using namespace std;
const int N=2e5+5,M=1e3+5;
int t,n,m,f[M][M];
char a[M],b[M],c[M<<1];
signed main()
{
    cin>>t;
    while(t--){
        cin>>(a+1)>>(b+1)>>(c+1);
        n=strlen(a+1);m=strlen(b+1);
        memset(f,0x3f,sizeof f);
        f[0][0]=0;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++){
                if(!i&&!j) continue;
                int res1=0x3f3f3f3f3f3f3f3f,res2=0x3f3f3f3f3f3f3f3f;
                if(i) res1=f[i-1][j]+(a[i]!=c[i+j]);
                if(j) res2=f[i][j-1]+(b[j]!=c[i+j]);
                f[i][j]=min(res1,res2);
            }
        cout<<f[n][m]<<endl;
    }
}

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

using namespace std;

 

#define int long long

#define vi vector<int>

#define printstl(stl) for(auto x: stl){print(x<<" ");}print(endl)

#define var(x) int x; cin>>x;

#define sar(ar,x) sort(ar,ar+x);

#define sv(v) sort(v.begin(),v.end());

#define srv(v) sort(v.rbegin(),v.rend());

#define pb push_back

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

#define ld long double

#define YES cout<<"YES"<<endl;

#define NO cout<<"NO"<<endl;

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

const int M=1e9+7;



void solve(){

string a,b,c;

cin>>a>>b>>c;

int n=a.size(),m=b.size();

vector<vector<int>> dp(n+1,vector<int>(m+1,0));



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

    if(i>0 && a[i-1]==c[i-1]){

        dp[i][0]=dp[i-1][0];

    }

    else if(i>0 && a[i-1]!=c[i-1]){

        dp[i][0]=dp[i-1][0]+1;

    }

    else{

        for(int j=1;j<=m;j++){

            if(b[j-1]==c[j-1]){

                dp[0][j]=dp[0][j-1];

            }

            else{

                dp[0][j]=dp[0][j-1]+1;

            }

        }

        continue;

    }

    for(int j=1;j<=m;j++){

        dp[i][j]=min(a[i-1]==c[i+j-1]?dp[i-1][j]:dp[i-1][j]+1,b[j-1]==c[i+j-1]?dp[i][j-1]:dp[i][j-1]+1);

    }

}

  cout<<dp[n][m]<<endl;

}

 



signed main(){

ios_base::sync_with_stdio(false);

cin.tie(NULL);

cout.tie(NULL);





var(t);

while(t--){

    solve();



    }

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

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

void solv() {
    ll l, r;
    cin >> l >> r;

  
    ll msb_diff = 0;
    for (ll bit = 31; bit >= 0; --bit) {
        if ((l & (1LL << bit)) != (r & (1LL << bit))) {
            msb_diff = bit;
            break;
        }
    }

    
    ll a= l|(1LL <<(msb_diff)) - 1; 
    ll b=a+1;
    ll c=a==l? r:l;
   

    cout << a<< " " << b << " " << c<< endl;
}

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

    int t;
    cin >> t;
    while (t--) {
        solv();
    }

    return 0;
}


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

#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

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

    // int max_val = l;

    // for(int i=0;i<30;i++){
    //     int num = pow(2,i);
    //     if(num>=l&&num<=r) max_val=max(max_val,num);
    // }

    // // If-else case
    // int a,b,c;

    // if(max_val==l){

    //     a=l;
    //     c=r;
    //     int num1 = -1;

    //     for(int i=l+1;i<r;i++){
    //         if(num1<=((a^i)+(c^i))){
    //             num1 = max(num1,(a^i+c^i));
    //             b=i;
    //         }
    //     }

    // }else if(max_val==r){

    //     a=r;
    //     b=r-1;
    //     c=l;

    // }else{

    //     a=max_val;
    //     b=a-1;
    //     int check1 = (a^r)+(b^r);
    //     int check2 = (a^l)+(b^l);
    //     if(check1>check2) c=r;
    //     else c=l; 
    //     if(b==l) c=r;

    // }
    //     cout<<a<<" "<<b<<" "<<c<<endl;

    int l, r;
    cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r); // Trailing zeroes of l^r
    int a =(pow(2,k) - 1);
    a=a|l;
    int b = a + 1; 
    int c = (a == l ? r : l);
    cout << a << " " << b << " " << c << "\n";
}

signed main() {
    fastio();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

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

    for (int i = 0; i < t; i++) {
         solve(i);
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

void solve() {
    long long int n; cin>> n;
    vector<long long int> arr(n+1);
    long long int sum = 0;
    for(int i =1; i<=n; i++) cin>> arr[i], sum += arr[i];
    
    long long size = n;
    for(int i =1; i< n; i++){
      
      long long int temp =0;
      for(int i = 1; i<size; i++){
        arr[i] = arr[i+1] -arr[i];
        temp += arr[i];
      }
      size--;
      
      sum = max(sum, abs(temp));
    }
    
    cout<< sum << endl;
    
}

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


Solution 2 (runtime: 46 ms):
// #pragma GCC optimize("O2,unroll-loops")
// #pragma GCC target("avx,avx2")
// #include "atcoder/all"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MOD1000000007 = 1000000007;
const int MOD998244353 = 998244353;
const double PI = 3.14159265358979323846264338327950288;
using namespace std;

void solve()
{
    int n;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll ans = accumulate(arr.begin(),arr.end(),0ll);
    while(n>1){
        n-=1;
        for(int i = 0;i<n;i++) arr[i] = arr[i+1]-arr[i];
        arr.pop_back();
        ans = max(ans,abs(accumulate(arr.begin(),arr.end(),0ll)));
    }
    cout<<ans<<endl;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int testcase = 1;
    cin >> testcase;
    // scanf("%d\n", &testcase);
    while (testcase--)
        solve();
    return 0;
}