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

Solution 1 (runtime: 62 ms):
//JAI SHREE RAM || SHREE GAJANAN MAHARAJ KI JAY || SHREE PANCHKRISHNAAVATAR KI JAY
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (ll i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, false, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define mod 1000000007
#define in(x) ll x; cin>>x;
#define bs(vec,i, ch) binary_search(vec.begin() + i, vec.end(), ch)
#define ub(vec,i, ch) upper_bound(vec.begin() + i, vec.end(), ch)
#define lb(vec,i, ch) lower_bound(vec.begin() + i, vec.end(), ch)
#define testc int t;cin>>t;while(t--)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef unsigned long long ull;
typedef long double lld;
const int N = 1e9+7;
 
 
//ASCII VALUES: A:65 a:97 0:48


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "<<endl;} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "<<endl;} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " "<<endl;} cerr << "]";}
//For checking substring
long long isSubstring(string s1, string s2)
{
// using find method to check if s1 is
 // a substring of s2
if (s2.find(s1) != string::npos)
  return s2.find(s1);
return -1;
}




bool powerof2(int x){return (x && !(x&(x-1)));}
bool is_palindrome(const string &str) {
   for (int a = 0, b = int(str.size()) - 1; a < b; a++, b--)
     if (str[a] != str[b])
         return false;
 return true;}
bool isprime(int n)
{
   // Corner cases
if (n <= 1)
   return false;
if (n <= 3)
return true;
 // This is checked so that we can skip middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
           return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;}
void sieve(int n) {
  vector<bool> prime(n + 1, true);
  prime[0] = prime[1] = false; // 0 and 1 are not prime numbers
for (int p = 2; p * p <= n; p++) {
 if (prime[p]) {
for (int i = p * p; i <= n; i += p) {
prime[i] = false;
}
}
 }
cout << "Prime numbers up to " << n << " are: ";
for (int p = 2; p <= n; p++) {
 if (prime[p]) {
 cout << p << " ";
 }
}
cout << endl;
}
//this does (x^y)%N
ll mod_exp(ll x, ll y) {
ll result = 1;
x %= N;
while (y > 0) {
if (y & 1)
 result = (result * x) % N;
     y >>= 1;
 x = (x * x) % N;
}
return result;
   }
const int MAX = 200000; // Adjust as needed
    ll fact[MAX + 1], inv_fact[MAX + 1];




void precompute_factorials() {
fact[0] = 1;
 for (int i = 1; i <= MAX; i++) {
 fact[i] = (fact[i - 1] * i) % N;
}
inv_fact[MAX] = mod_exp(fact[MAX], N - 2); // Using Fermat's Little Theorem
for (int i = MAX - 1; i >= 0; i--) {
 inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % N;
}
}
ll nCk(ll n, ll k) {
if (k > n || k < 0) return 0;
return (((fact[n] * inv_fact[k]) % N) * inv_fact[n - k]) % N;}
//this does prime factorisation of n
vector<long long> trial_division1(long long n) {
vector<long long> factorization;
    for (long long d = 2; d * d <= n; d++) {
while (n % d == 0) {
 factorization.push_back(d);
n /= d;}
}
if (n >1)
factorization.push_back(n);
return factorization;
}














struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
   static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  return splitmix64(x + FIXED_RANDOM);
}
};
typedef unordered_map<long long, ll, custom_hash> safe_map;
//typedef gp_hash_table<long long, int, custom_hash> safe_hash_table;
bool isPerfectSquare(ll num) {
if (num < 0) return false; 
ll root = sqrt(num);      
return root * root == num; 
}
int mex(vector<int> const& A) {
 static bool used[MAX+1] = { 0 };
 for (int x : A) {
if (x <= MAX)
 used[x] = true;
}
 int result = 0;
 while (used[result])
++result;
 for (int x : A) {
 if (x <= MAX)
 used[x] = false;
}
return result;
}




int main(){
ios::sync_with_stdio(0);
cin.tie(0);

testc{
    in(n);vll a(n);
    fo(i,n) cin>>a[i];

  ll sum1=accumulate(all(a),0ll);
ll best=sum1;
    while(a.size()>1){
        ll newsize=a.size();
        vll temp;
        fo(i,newsize-1){
            temp.pb(a[i+1]-a[i]);
        }
    ll sum2=abs(accumulate(all(temp),0ll));
    best=max(sum2,best);
    a=temp;

    }

    cout<<best<<endl;
}


return 0;
}
//JAI SHREE RAM || SHREE GAJANAN MAHARAJ KI JAY || SHREE PANCHKRISHNAAVATAR KI JAY

Solution 2 (runtime: 62 ms):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1ll<<x)
map<vector<int>,int>mp;
int solve(vector<int>v)
{
  if(v.size()==1)return v[0];
  if(mp.count(v))return mp[v];
  vector<int>temp;
  int sum=v[0];
  for(int i=1;i<v.size();i++)
  {
    temp.push_back(v[i]-v[i-1]);sum+=v[i];
  }
  int op1=solve(temp);
  
  temp.clear();
  for(int i=0;i<v.size()-1;i++)
  {
    temp.push_back(v[i]-v[i+1]);
  }
  int op2=solve(temp);
  return mp[v]=max({op1,op2,sum});
}
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
  {int n;cin>>n;
  vector<int>vec;
  vec.resize(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  cout<<solve(vec)<<"\n";
}
}