Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

// Convert a vector of ints into a string key for memoization.
string vecToKey(const vector<int>& arr) {
    // We join numbers with a comma.
    string key;
    for (int x : arr) {
        key += to_string(x) + ",";
    }
    return key;
}

unordered_map<string, ll> memo;

ll F(const vector<int>& arr) {
    // Casos base
    string key = vecToKey(arr);
    if (memo.count(key))
        return memo[key];       // memoizacao
    
    if (arr.size() == 1)
        return memo[key] = arr[0];

    // Recursao    
    // Soma do original
    ll sum1 = 0;
    for (int x : arr)
        sum1 += x;
    
    // Soma do invertido
    vector<int> rev(arr);
    reverse(rev.begin(), rev.end());
    ll sum2 = 0;
    for (int x : rev)
        sum2 += x;
    
    // Sequencia original
    vector<int> diff1;
    for (size_t i = 0; i < arr.size()-1; i++){
        diff1.push_back(arr[i+1] - arr[i]);
    }
    
    // Sequencia invertida
    vector<int> diff2;
    for (size_t i = 0; i < rev.size()-1; i++){
        diff2.push_back(rev[i+1] - rev[i]);
    }
    
    ll ans = max({ sum1, sum2, F(diff1), F(diff2) });
    memo[key] = ans;
    return ans;
}
 
int main(){
    BOOST
    
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        memo.clear();
        cout << F(arr) << "\n";
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

// Converter vector de long long para string para memoizacao
string vecToKey(const vector<ll>& arr) {
    string key;
    for (ll x : arr) {
        key += to_string(x) + ",";
    }
    return key;
}

unordered_map<string, ll> memo;

ll F(const vector<ll> &arr) {
    // Casos base
    string key = vecToKey(arr);
    if (memo.count(key))
        return memo[key];       // memoizacao
    
    if (arr.size() == 1)
        return memo[key] = arr[0];

    // Recursao    
    // Soma do original
    ll sum1 = 0;
    for (int x : arr)
        sum1 += x;
    
    // Soma do invertido
    vector<ll> rev(arr);
    reverse(rev.begin(), rev.end());
    ll sum2 = 0;
    for (int x : rev)
        sum2 += x;
    
    // Sequencia original
    vector<ll> diff1;
    for (size_t i = 0; i < arr.size()-1; i++){
        diff1.push_back(arr[i+1] - arr[i]);
    }
    
    // Sequencia invertida
    vector<ll> diff2;
    for (size_t i = 0; i < rev.size()-1; i++){
        diff2.push_back(rev[i+1] - rev[i]);
    }
    
    ll ans = max({ sum1, sum2, F(diff1), F(diff2) });
    memo[key] = ans;
    return ans;
}
 
int main(){
    BOOST
    
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<ll> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        memo.clear();
        cout << F(arr) << "\n";
    }
    return 0;
}