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

Code 1:
//Coded by:-suvampaul
#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
#include<stack>
#include<deque>
#include<queue>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<numeric>
#include<string>
#include<iterator>
#include<limits>
using namespace std;


#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define vpii vector<pii>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define vll vector<ll>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1'000'000'007


const int MAXN = 100'005;
int spf[MAXN];
ll fac1[MAXN], fac2[MAXN], inv[MAXN];
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template <typename C, typename T = std::decay_t<decltype(*begin(std::declval<C>()))>, typename std::enable_if<!std::is_same<C, std::string>::value>::type* = nullptr>
std::ostream& operator<<(std::ostream& os, const C& container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto& x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}
vector<string> vec_splitter(string S)
{
    S += ',';
    vector<string> res;
    while (!S.empty())
    {
        res.push_back(S.substr(0, S.find(',')));
        S = S.substr(S.find(',') + 1);
    }
    return res;
}

template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T)
{
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DEBUG
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

bool isPerfectSquare(long double x)
{
    if (x >= 0) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

bool isPowerof2(int n, int) {
    return (n && !(n & n - 1));
}

string decimalToBin(ll N)
{
    string B_Number = "";
    int c = 0;
    while (N != 0) {
        if (N % 2 == 0) {
            B_Number = "0" + B_Number;
        }
        else B_Number = "1" + B_Number;
        N = N / 2;
        c++;
    }
    
    for (int i = c + 1; i <= 30; i++) {
        B_Number = "0" + B_Number;
    }
    
    return B_Number;
}

int binaryToDecimal(ll n)
{
    ll num = n;
    int dec_value = 0;
    int base = 1;
    ll temp = num;

    while (temp) {
        int last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}


ll min(ll a, ll b) {
    return a < b ? a : b;
}
ll max(ll a, ll b) {
    return a > b ? a : b;
}
ll power(ll a, ll b, ll Mod) {
    if (b == 0) {
        return 1;
    }
    ll ans = power(a, b / 2, Mod);
    ans *= ans;
    ans %= Mod;
    if (b % 2) {
        ans *= a;
    }
    return ans % Mod;
}

ll getMin(vector<ll> arr, int n)
{
    ll res = arr[0];
    for (int i = 1; i < n; i++)
        res = min(res, arr[i]);
    return res;
}
ll getMax(vector<ll> arr, int n)
{
    ll res = arr[0];
    for (int i = 1; i < n; i++)
        res = max(res, arr[i]);
    return res;
}

string adder(string s1, string s2) {
    vector<int> num;
    int len1 = s1.length();
    int len2 = s2.length();
    int len = max(len1, len2);
    for (int i = len1 + 1; i <= len; i++) s1 = "0" + s1;
    for (int i = len2 + 1; i <= len; i++) s2 = "0" + s2;
    for (int i = 0; i < len + 1; i++) num.push_back(0);
    int c = num.size();
    for (int i = 0; i < len; i++) {
        int x1 = s1[len - 1 - i] - '0';
        int x2 = s2[len - 1 - i] - '0';
        num[c - 1 - i] += (x1 + x2);
        num[c - 1 - i - 1] += num[c - 1 - i] / 10;
        num[c - 1 - i] = num[c - 1 - i] % 10;
    }
    string ans = "";
    int idx = 0;
    for (int i = 0; i < c; i++) {
        if (num[i] != 0) {
            idx = i; break;
        }
    }
    for (int i = idx; i < c; i++) {
        ans += to_string(num[i]);
    }
    return ans;
}

ll accurateFloor(ll a, ll b) {
    ll val = a / b;
    while (val * b > a)
        val--;
    return val;
}

vi formSum(ll n, ll val) {
    vi a(n+1);
    ll s = val;
    int idx = n;
    while (s!=0) {
        if (s > idx) {
            a[idx] = 1;
            s -= idx;
            idx--;
        }
        else {
            a[s] = 1;
            break;
        }
    }
    return a;
}

void place(vector<int>& arr, int l, int r, int i, vector<int>& A) {
    if (l > r) return;
    int idx = (l + r) / 2;
    arr[idx] = A[i];
    place(arr, l, idx - 1, 2 * i + 1, A);
    place(arr, idx + 1, r, 2 * i + 2, A);
}
struct Node
{
    int data;
    Node* left, * right;
};

/* Helper function that allocates a
new node */
Node* newNode(int data)
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->data = data;
    node->left = node->right = NULL;
    return (node);
}

// Function to insert nodes in level order
Node* insertLevelOrder(vector<int> arr,
    int i, int n)
{
    Node* root = nullptr;
    // Base case for recursion
    if (i < n)
    {
        root = newNode(arr[i]);

        // insert left child
        root->left = insertLevelOrder(arr,
            2 * i + 1, n);

        // insert right child
        root->right = insertLevelOrder(arr,
            2 * i + 2, n);
    }
    return root;
}

// Function to print tree nodes in
// InOrder fashion
void inOrder(Node* root, vector<int>& v)
{
    if (root != NULL)
    {
        inOrder(root->left, v);
        v.push_back(root->data);
        inOrder(root->right, v);
    }
}

bool ingrid(int x, int y, int n, int m) {
    if (x >= 0 && x < n && y >= 0 && y < m) return true;
    else return false;
}

set<string> st;
void solve(string s,int K){
    int cnt = 0;
    for (int i = 0; i < 7; i++) {
        if (s[i] == '?') cnt++;
    }
    if (cnt == 0) {
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += (s[i] - '0');
        }
        if (sum == K) st.insert(s);
        return;
    }

    int idx = 0;
    for (int i = 0; i < 7; i++) {
        if (s[i] == '?') {
            idx = i; break;
        }
    }
    string f = "";
    for (int i = 0; i < idx; i++) f = f + s[i];
    string g = "";
    for (int i = idx + 1; i < s.length(); i++) g = g + s[i];
    for (int i = 0; i <= 8; i++) {
        solve(f + to_string(i) + g, K);
    }

}

int maximumpoints(vector<vector<int> > arr, int n, int x, int y) {
    // code here
    vector<vector<int>> m(1001, vector<int>(1001, 0));
    for (int i = 0; i < n; i++) {
        m[arr[i][0]][arr[i][1]]++;
    }
    int ans = 0;
    for (int i = 1; i <= 1000; i++) {
        for (int j = 1; j <= 1000; j++) {
            m[i][j] += (m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]);
            if (i - x > 0 && j - y > 0) {
                ans = max(ans, m[i][j] + m[i - x - 1][j - y - 1] - m[i][j - y - 1] - m[i - x - 1][j]);
            }
        }
    }
    return ans;
}

string func(string s, int k) {
    stack<pair<char,int>> st;
    st.push({ '#',0});
    for (int i = 0; i < s.length(); i++) {
        char c = s[i];
        if (c == st.top().first) {
            st.top().second++;
        }
        else {
            st.push({ c,1 });
        }
        
        if (st.top().second >= k) {
            st.pop();
        }
    }

    string ans = "";
    
    while (!st.empty()) {
        pair<char,int> p = st.top();
        st.pop();
        char ch = p.first;
        int num = p.second;
        for (int var = 0; var < num; var++) {
            ans = ch + ans;
        }
    }
    return ans;
}

bool cmp(pair<int, string> p1, pair<int, string> p2) {
    if (p1.first < p2.first) return true;
    /*else{
        if(p1.second.length()<p2.second.length()) return true;
        else{
            if(p1.second<p2.second) return true;
        }
    }*/
    return false;
}

bool strcmp(string s1, string s2) {
    if (s1.length() < s2.length()) return true;
    else {
        if (s1 < s2) return true;
    }
    return false;
}

bool cmp1(pair<int, int> p1, pair<int, int> p2) {
    if (p1.first != p2.first) return p1.first < p2.first;
    else p1.second < p2.second;
}

bool cmp2(pair<int, int> p1, pair<int, int> p2) {
    return p1.second < p2.second;
}


string MostFrequent(string str) {
    string s = "";
    map<string, int> mp;
    for (int i = 0; i < str.length(); i++) {
        if (str[i] != ' ') s = s + str[i];
        else {
            mp[s]++;
            s = "";
        }
    }
    mp[s]++;
    map<string, int>::iterator it;
    string ans = "";
    int cnt = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
        if (it->second > cnt) {
            ans = it->first;
            cnt = it->second;
        }
    }
    return ans;
}

vector<ll> reverse(vll vec) {
    int sz = vec.size();
    for (int i = 0; i < sz / 2; i++) vec[i] = vec[sz - 1 - i];
    return vec;
}
vector<ll> replace(vll vec) {
    int sz = vec.size();
    vll nv;
    rep(i, sz - 1) { nv.push_back(vec[i + 1] - vec[i]); }
    return nv;
}

#define print(vec) rep(i,vec.size()) cout<<vec[i]<<' '; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    rep(test, t) {
        int n; cin >> n;
        vll a;
        ll ans = 0;
        rep(i, n) {
            int var; cin >> var; a.pb(var);
            ans += var;
        }
        for (int c = 0; c < n - 1; c++) {
            ans = max(ans, abs(a[a.size() - 1] - a[0]));
            a = replace(a);
        }
        cout << ans << endl;
    }

    return 0;
}








Code 2:
//Coded by:-suvampaul
#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
#include<stack>
#include<deque>
#include<queue>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<numeric>
#include<string>
#include<iterator>
#include<limits>
using namespace std;


#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define vpii vector<pii>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define vll vector<ll>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1'000'000'007


const int MAXN = 100'005;
int spf[MAXN];
ll fac1[MAXN], fac2[MAXN], inv[MAXN];
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template <typename C, typename T = std::decay_t<decltype(*begin(std::declval<C>()))>, typename std::enable_if<!std::is_same<C, std::string>::value>::type* = nullptr>
std::ostream& operator<<(std::ostream& os, const C& container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto& x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}
vector<string> vec_splitter(string S)
{
    S += ',';
    vector<string> res;
    while (!S.empty())
    {
        res.push_back(S.substr(0, S.find(',')));
        S = S.substr(S.find(',') + 1);
    }
    return res;
}

template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T)
{
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DEBUG
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

bool isPerfectSquare(long double x)
{
    if (x >= 0) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

bool isPowerof2(int n, int) {
    return (n && !(n & n - 1));
}

string decimalToBin(ll N)
{
    string B_Number = "";
    int c = 0;
    while (N != 0) {
        if (N % 2 == 0) {
            B_Number = "0" + B_Number;
        }
        else B_Number = "1" + B_Number;
        N = N / 2;
        c++;
    }
    
    for (int i = c + 1; i <= 30; i++) {
        B_Number = "0" + B_Number;
    }
    
    return B_Number;
}

int binaryToDecimal(ll n)
{
    ll num = n;
    int dec_value = 0;
    int base = 1;
    ll temp = num;

    while (temp) {
        int last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}


ll min(ll a, ll b) {
    return a < b ? a : b;
}
ll max(ll a, ll b) {
    return a > b ? a : b;
}
ll power(ll a, ll b, ll Mod) {
    if (b == 0) {
        return 1;
    }
    ll ans = power(a, b / 2, Mod);
    ans *= ans;
    ans %= Mod;
    if (b % 2) {
        ans *= a;
    }
    return ans % Mod;
}

ll getMin(vector<ll> arr, int n)
{
    ll res = arr[0];
    for (int i = 1; i < n; i++)
        res = min(res, arr[i]);
    return res;
}
ll getMax(vector<ll> arr, int n)
{
    ll res = arr[0];
    for (int i = 1; i < n; i++)
        res = max(res, arr[i]);
    return res;
}

string adder(string s1, string s2) {
    vector<int> num;
    int len1 = s1.length();
    int len2 = s2.length();
    int len = max(len1, len2);
    for (int i = len1 + 1; i <= len; i++) s1 = "0" + s1;
    for (int i = len2 + 1; i <= len; i++) s2 = "0" + s2;
    for (int i = 0; i < len + 1; i++) num.push_back(0);
    int c = num.size();
    for (int i = 0; i < len; i++) {
        int x1 = s1[len - 1 - i] - '0';
        int x2 = s2[len - 1 - i] - '0';
        num[c - 1 - i] += (x1 + x2);
        num[c - 1 - i - 1] += num[c - 1 - i] / 10;
        num[c - 1 - i] = num[c - 1 - i] % 10;
    }
    string ans = "";
    int idx = 0;
    for (int i = 0; i < c; i++) {
        if (num[i] != 0) {
            idx = i; break;
        }
    }
    for (int i = idx; i < c; i++) {
        ans += to_string(num[i]);
    }
    return ans;
}

ll accurateFloor(ll a, ll b) {
    ll val = a / b;
    while (val * b > a)
        val--;
    return val;
}

vi formSum(ll n, ll val) {
    vi a(n+1);
    ll s = val;
    int idx = n;
    while (s!=0) {
        if (s > idx) {
            a[idx] = 1;
            s -= idx;
            idx--;
        }
        else {
            a[s] = 1;
            break;
        }
    }
    return a;
}

void place(vector<int>& arr, int l, int r, int i, vector<int>& A) {
    if (l > r) return;
    int idx = (l + r) / 2;
    arr[idx] = A[i];
    place(arr, l, idx - 1, 2 * i + 1, A);
    place(arr, idx + 1, r, 2 * i + 2, A);
}
struct Node
{
    int data;
    Node* left, * right;
};

/* Helper function that allocates a
new node */
Node* newNode(int data)
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->data = data;
    node->left = node->right = NULL;
    return (node);
}

// Function to insert nodes in level order
Node* insertLevelOrder(vector<int> arr,
    int i, int n)
{
    Node* root = nullptr;
    // Base case for recursion
    if (i < n)
    {
        root = newNode(arr[i]);

        // insert left child
        root->left = insertLevelOrder(arr,
            2 * i + 1, n);

        // insert right child
        root->right = insertLevelOrder(arr,
            2 * i + 2, n);
    }
    return root;
}

// Function to print tree nodes in
// InOrder fashion
void inOrder(Node* root, vector<int>& v)
{
    if (root != NULL)
    {
        inOrder(root->left, v);
        v.push_back(root->data);
        inOrder(root->right, v);
    }
}

bool ingrid(int x, int y, int n, int m) {
    if (x >= 0 && x < n && y >= 0 && y < m) return true;
    else return false;
}

set<string> st;
void solve(string s,int K){
    int cnt = 0;
    for (int i = 0; i < 7; i++) {
        if (s[i] == '?') cnt++;
    }
    if (cnt == 0) {
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += (s[i] - '0');
        }
        if (sum == K) st.insert(s);
        return;
    }

    int idx = 0;
    for (int i = 0; i < 7; i++) {
        if (s[i] == '?') {
            idx = i; break;
        }
    }
    string f = "";
    for (int i = 0; i < idx; i++) f = f + s[i];
    string g = "";
    for (int i = idx + 1; i < s.length(); i++) g = g + s[i];
    for (int i = 0; i <= 8; i++) {
        solve(f + to_string(i) + g, K);
    }

}

int maximumpoints(vector<vector<int> > arr, int n, int x, int y) {
    // code here
    vector<vector<int>> m(1001, vector<int>(1001, 0));
    for (int i = 0; i < n; i++) {
        m[arr[i][0]][arr[i][1]]++;
    }
    int ans = 0;
    for (int i = 1; i <= 1000; i++) {
        for (int j = 1; j <= 1000; j++) {
            m[i][j] += (m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]);
            if (i - x > 0 && j - y > 0) {
                ans = max(ans, m[i][j] + m[i - x - 1][j - y - 1] - m[i][j - y - 1] - m[i - x - 1][j]);
            }
        }
    }
    return ans;
}

string func(string s, int k) {
    stack<pair<char,int>> st;
    st.push({ '#',0});
    for (int i = 0; i < s.length(); i++) {
        char c = s[i];
        if (c == st.top().first) {
            st.top().second++;
        }
        else {
            st.push({ c,1 });
        }
        
        if (st.top().second >= k) {
            st.pop();
        }
    }

    string ans = "";
    
    while (!st.empty()) {
        pair<char,int> p = st.top();
        st.pop();
        char ch = p.first;
        int num = p.second;
        for (int var = 0; var < num; var++) {
            ans = ch + ans;
        }
    }
    return ans;
}

bool cmp(pair<int, string> p1, pair<int, string> p2) {
    if (p1.first < p2.first) return true;
    /*else{
        if(p1.second.length()<p2.second.length()) return true;
        else{
            if(p1.second<p2.second) return true;
        }
    }*/
    return false;
}

bool strcmp(string s1, string s2) {
    if (s1.length() < s2.length()) return true;
    else {
        if (s1 < s2) return true;
    }
    return false;
}

bool cmp1(pair<int, int> p1, pair<int, int> p2) {
    if (p1.first != p2.first) return p1.first < p2.first;
    else p1.second < p2.second;
}

bool cmp2(pair<int, int> p1, pair<int, int> p2) {
    return p1.second < p2.second;
}


string MostFrequent(string str) {
    string s = "";
    map<string, int> mp;
    for (int i = 0; i < str.length(); i++) {
        if (str[i] != ' ') s = s + str[i];
        else {
            mp[s]++;
            s = "";
        }
    }
    mp[s]++;
    map<string, int>::iterator it;
    string ans = "";
    int cnt = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
        if (it->second > cnt) {
            ans = it->first;
            cnt = it->second;
        }
    }
    return ans;
}

vector<int> reverse(vi vec) {
    int sz = vec.size();
    for (int i = 0; i < sz / 2; i++) vec[i] = vec[sz - 1 - i];
    return vec;
}
vector<int> replace(vi vec) {
    int sz = vec.size();
    vi nv;
    rep(i, sz - 1) { nv.push_back(vec[i + 1] - vec[i]); }
    return nv;
}

#define print(vec) rep(i,vec.size()) cout<<vec[i]<<' '; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    rep(test, t) {
        int n; cin >> n;
        vi a;
        ll ans = 0;
        rep(i, n) {
            int var; cin >> var; a.pb(var);
            ans += var;
        }
        for (int c = 0; c < n - 1; c++) {
            ans = max(ans, abs(a[a.size() - 1] - a[0]));
            a = replace(a);
        }
        cout << ans << endl;
    }

    return 0;
}








Answer: 1