Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    while(k--)
    {
        long long n;
        cin >> n;
        vector<long long> a(n);
        long long sum = 0;
        for(long long i = 0; i < n; i++)
        {
            cin >> a[i];
            sum+=a[i];
        }
        vector<long long> c = a;
        reverse(a.begin(), a.end());
        vector<vector<long long>> matrix;
        matrix.push_back(a);
        matrix.push_back(c);
        bool ok = true;
        while(ok)
        {
            vector<vector<long long>> s = matrix;
            long long mn = matrix[0].size();
            for(long long i = matrix.size()-1; i>=0; i--)
            {
                vector<long long> t;
                for(long long j = 0; j < matrix[i].size()-1; j++)
                {
                    t.push_back(s[i][j+1]-s[i][j]);
                }
                vector<long long> u;
                reverse(s[i].begin(), s[i].end());
                for(long long j = 0; j < matrix[i].size()-1; j++)
                {
                    u.push_back(s[i][j+1]-s[i][j]);
                }
                if(find(s.begin(), s.end(), u)==s.end())
                {
                    matrix.push_back(u);
                }
                if(find(s.begin(), s.end(), t)==s.end())
                {
                    matrix.push_back(t);
                }
            }
            vector<long long> p;
            for(long long i = 0; i < matrix.size(); i++)
            {
                p.push_back(matrix[i].size());
            }
            sort(p.begin(), p.end());
            if(p[0]==1)
            {
                ok=false;
            }
        }
        for(int i = 0; i < matrix.size(); i++)
        {
            long long sum1 = 0;
            for(int j = 0; j < matrix[i].size(); j++)
            {
                sum1+=matrix[i][j];
            }
            sum=max(sum, sum1);
        }
        cout << sum << endl;
    }
}

Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    while(k--)
    {
        long long n;
        cin >> n;
        vector<long long> a(n);
        long long sum = 0;
        for(long long i = 0; i < n; i++)
        {
            cin >> a[i];
            sum+=a[i];
        }
        if(n==1)
        {
            cout << sum << endl;
        }
        else{
        vector<long long> c = a;
        reverse(a.begin(), a.end());
        vector<vector<long long>> matrix;
        matrix.push_back(a);
        matrix.push_back(c);
        bool ok = true;
        while(ok)
        {
            vector<vector<long long>> s = matrix;
            long long mn = matrix[0].size();
            for(long long i = matrix.size()-1; i>=0; i--)
            {
                vector<long long> t;
                for(long long j = 0; j < matrix[i].size()-1; j++)
                {
                    t.push_back(s[i][j+1]-s[i][j]);
                }
                vector<long long> u;
                reverse(s[i].begin(), s[i].end());
                for(long long j = 0; j < matrix[i].size()-1; j++)
                {
                    u.push_back(s[i][j+1]-s[i][j]);
                }
                if(find(s.begin(), s.end(), u)==s.end())
                {
                    matrix.push_back(u);
                }
                if(find(s.begin(), s.end(), t)==s.end())
                {
                    matrix.push_back(t);
                }
            }
            vector<long long> p;
            for(long long i = 0; i < matrix.size(); i++)
            {
                p.push_back(matrix[i].size());
            }
            sort(p.begin(), p.end());
            if(p[0]==1)
            {
                ok=false;
            }
        }
        for(int i = 0; i < matrix.size(); i++)
        {
            long long sum1 = 0;
            for(int j = 0; j < matrix[i].size(); j++)
            {
                sum1+=matrix[i][j];
            }
            sum=max(sum, sum1);
        }
        cout << sum << endl;
    }
    }
}