ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define endl "\n"
#define all(a) a.begin(), a.end()
#define ll long long
#define ull unsigned long long
#define inf 0x7fffffff;
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define rrp(i, l, r) for(int i = l; i >= r; --i)
#define fucking_go(x) int t; cin >> t; while(t--) x()
using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int> >;
using vvl = vector<vector<ll> >;
using vpii = vector<pair<int, int> >;
using vpll = vector<pair<ll, ll> >;
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll INF = 1e18;

int n;
set<int> g[200010];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) g[i].clear();
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].insert(v);
        g[v].insert(u);
    }
    if (n == 2) {
        cout << 0 << endl;
        return;
    }
    vi del(n + 1);
    vi cnt(n + 1);
    for (int i = 1; i <= n; i++) {
        if (g[i].size() == 1) cnt[(*g[i].begin())]++;
    }
    int mx = -1, index = 0;
    for (int i = 1; i <= n; i++) {
        if (cnt[i] > mx) {
            mx = cnt[i];
            index = i;
        }
    }
    del[index] = 1;
    for (int x : g[index]) {
        g[x].erase(index);
        g[index].erase(x);
        if (g[x].size() == 1) {
            cnt[(*g[x].begin())]++;
        }
    }
    mx = -1, index = 0;
    for (int i = 1; i <= n; i++) {
        if (del[i] == 0) {
            if (cnt[i] > mx) {
                mx = cnt[i];
                index = i;
            }
        }
    }
    if (mx == -1) {
        for (int i = 1; i <= n; i++) {
            if (del[i] == 0) {
                del[i] = 1;
                break;
            }
        }
    }
    else {
        del[index] = 1;
        for (int x : g[index]) {
            g[x].erase(index);
            g[index].erase(x);
        }
    }
    int ans = 0;
    vi flag(n + 1);
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (del[i] == 0) {
            q.push(i);
            ans++;
            while (!q.empty()) {
                int x = q.front();
                q.pop();
                del[x] = 1;
                for (int y : g[x]) {
                    if (del[y] == 0) {
                        q.push(y);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
// helper();
// init();
fucking_go(solve);
//solve();

return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define ll long long
#define int long long
#define double long double
#define Int __int128
#define pb push_back
#define eb emplace_back
#define MAX_LOG 21
#define ff first
#define ss second
#define RI register int
#define CI const int&
#define ull unsigned long long
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<ll,ll> PLL;
typedef pair<int,int>PII;
ll gcd(ll a,ll b)
{
    if(b) while((a%=b)&&(b%=a));
    return a+b;
}//最大公约数函数
ll spid(ll a,ll b,ull p)
{
    ll ans=1;
    while(b)
    {
        if(b&1)ans=(Int)ans*a%p;
        b>>=1;
        a=(Int)a*a%p;
    }
    return ans;
}//快速幂函数
///泡沫在阳光下闪烁，像星辰在寂静得夜空中闪耀

///秋雨
const ll N=2e5+10;
ll mod=998244353;
void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n+1);
    vector<PLL>b(n+1);
    for(int i=1; i<=n; i++)cin>>a[i],b[i].ss=i,b[i].ff=a[i];
    sort(a.begin(),a.end());
    ll ans=0;
    vector<PLL>vec;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(a[i]==b[j].ff)continue;
            if(a[i]>b[j].ff&&i>b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]<b[j].ff&&i>b[j].ss)
            {
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]>b[j].ff&&i<b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
            }
            else
            {
                vec.pb({b[j].ff,a[i]});
                vec.pb({a[i],b[j].ff});
            }
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    reverse(vec.begin(),vec.end());
    vector<ll>num(n+1,0);
    for(int i=1;i<=n;i++)num[i]=i;
    ll cnt=0;
    ll now=0;
    for(auto j:vec)
    {
        swap(num[j.ff],num[j.ss]);
        now++;
        bool ret=1;
        for(int j=1;j<=n;j++)
        {
            if(num[j]!=a[j])ret=0;
        }
        if(ret)cnt=now;
    }
    cout<<cnt<<'\n';
    for(auto i:vec)
    {
        if(cnt)
        cout<<i.ff<<' '<<i.ss<<'\n';
        else break;
        cnt--;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    while(t--)
    {
        solve();
    }
}
///在秋天邂逅， 在春天发芽，在夏天壮大，在秋天萧瑟，在冬天萎缩，

///而后，春天再度归来。
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

void solve()
{
    int l, r, a, b, c;
    std::cin >> l >> r;
    for (int i = 30; i >= 0; --i)
    {
        if ((l >> i & 1) ^ (r >> i & 1))
        {
            a = 1 << i;
            b = (1 << i) - 1;
            c = (b - 1 >= l ? b - 1 : a + 1);
            break;
        }
    }
    std::cout << a << " " << b << " " << c << "\n";
} 

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

    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

void solve()
{
    int l, r, a, b, c, base = 0;
    std::cin >> l >> r;
    for (int i = 30; i >= 0; --i)
    {
        if ((l >> i & 1) ^ (r >> i & 1))
        {
            a = 1 << i;
            b = (1 << i) - 1;
            c = (b - 1 >= l ? b - 1 : a + 1);
            break;
        }
        else if ((l >> i & 1) & (r >> i & 1)) base += 1 << i;
    }
    std::cout << a + base << " " << b + base << " " << c + base << "\n";
} 

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

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

void solve()
{
    int l, r, a, b, c;
    std::cin >> l >> r;
    for (int i = 30; i >= 0; --i)
    {
        if ((l >> i & 1) ^ (r >> i & 1))
        {
            a = 1 << i;
            b = (1 << i) - 1;
            c = (b - 1 >= l ? b - 1 : a + 1);
            break;
        }
    }
    std::cout << a << " " << b << " " << c << "\n";
} 

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

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

void solve()
{
    int l, r, a, b, c, base = 0;
    std::cin >> l >> r;
    for (int i = 30; i >= 0; --i)
    {
        if ((l >> i & 1) ^ (r >> i & 1))
        {
            a = 1 << i;
            b = (1 << i) - 1;
            c = (b - 1 >= l ? b - 1 : a + 1);
            break;
        }
        else if ((l >> i & 1) & (r >> i & 1)) base += 1 << i;
    }
    std::cout << a + base << " " << b + base << " " << c + base << "\n";
} 

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

    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

void solve()
{
    int l, r, a, b, c, base = 0;
    std::cin >> l >> r;
    for (int i = 30; i >= 0; --i)
    {
        if ((l >> i & 1) ^ (r >> i & 1))
        {
            a = (1 << i) + base;
            b = (1 << i) - 1 + base;
            c = (b - 1 >= l ? b - 1 : a + 1);
            break;
        }
        else if ((l >> i & 1) & (r >> i & 1)) base += 1 << i;
    }
    std::cout << a << " " << b << " " << c << "\n";
} 

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

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


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define IOS1 std::ios::sync_with_stdio(false)
#define IOS2 std::cin.tie(nullptr)
#define mode1 1
#define mode2 1

using i32 = int;
using ui32 = unsigned int;
using i64 = long long;
using ui64 = unsigned long long;
using pii = std::pair<int, int>;
using ll = long long;
// using i128 = __int128;

constexpr i64 INF = 0x3f3f3f3f3f3f3f3f;
constexpr i64 INFINF = 0X7fffffffffffffff;
constexpr int inf = 1e9;
constexpr int mod = 998244353;

template <class T1, class T2>
std::istream& operator>>(std::istream& cin, std::pair<T1, T2>& a) { return cin >> a.first >> a.second; };
template <class T1, class T2>
std::ostream& operator<<(std::ostream& cout, std::pair<T1, T2>& a) { return cout << a.first << ' ' << a.second; };
template <class T>
std::ostream& operator<<(std::ostream& cout, std::vector<T>& a)
{
    for (int i = 0; i < a.size(); ++i)
        cout << a[i] << " \n"[i == a.size() - 1];
    return cout;
}

template<class T>
inline T read()
{
    T x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

template<class T>
inline void write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}

class Solution
{
public:
    void solve()
    {
        int n;
        std::cin >> n;
        std::vector<int> a(n), b;
        int tmp = -inf;
        for (int i = 0; i < n; ++i) std::cin >> a[i];
        std::function<void(std::vector<int> t)>dfs = [&](std::vector<int> t) -> void
        {
            tmp = std::max(tmp, std::accumulate(t.begin(), t.end(), 0));
            if (t.size() == 1) return;
            std::vector<int> x, y;
            for (int i = 1; i < t.size(); ++i)
            {
                x.emplace_back(t[i] - t[i - 1]);
            }
            dfs(x);
            // std::reverse(t.begin(), t.end());
            // for (int i = 1; i < t.size(); ++i)
            // {
            //     y.emplace_back(t[i] - t[i - 1]);
            // }
            // dfs(y);
        };
        dfs(a);
        std::cout << tmp << "\n";
    }
};

int main()
{
    IOS1;
    IOS2;

#if mode1
    int t;
    std::cin >> t;
    while (t--)
    {
        Solution().solve();
    }
#elif mode2
    Solution().solve();
#endif

    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << endl
#define in(x) cin >> x
#define int long long

void solve() {
    string a, b, c;
    in(a);
    in(b);
    in(c);

    int n = a.size();
    int m = b.size();
    int p = c.size();

    vector<vector<vector<int>>> hp(n + 1, vector<vector<int>>(m + 1, vector<int>(p + 1, -1)));

    function<int(int, int, int)> func = [&](int ind, int ind2, int ind3) -> int {
        if ((ind >= n && ind2 >= m) || ind3 == p) {
            return 0;
        }
        if (hp[ind][ind2][ind3] != -1) return hp[ind][ind2][ind3];

        int ans = INT_MAX;

        if (ind < n) {
            int cost = (a[ind] != c[ind3]) ? 1 : 0;
            ans = min(ans, func(ind + 1, ind2, ind3 + 1) + cost);
        }

        if (ind2 < m) {
            int cost = (b[ind2] != c[ind3]) ? 1 : 0;
            ans = min(ans, func(ind, ind2 + 1, ind3 + 1) + cost);
        }

        return hp[ind][ind2][ind3] = ans;
    };

    int res = func(0, 0, 0);
    out(res);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    in(t);
    while (t--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,string a,string b,string c){
    if(ind>=(a.size()) && ind2>=(b.size())){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    int ans=INT_MAX;
    if(ind<n){
    if(a[ind]==c[ind+ind2]){
        ans = min(ans,func(ind+1,ind2,a,b,c));
    }else{
        ans = min(ans,func(ind+1,ind2,a,b,c)+1);
    }
    }
    if(ind2<b.size()){
    if(b[ind2]==c[ind + ind2]){
        ans = min(ans,func(ind,ind2+1,a,b,c));
    }else{
        ans = min(ans,func(ind,ind2+1,a,b,c)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
int res = func(0,0,a,b,c);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << endl
#define in(x) cin >> x
#define int long long

void solve() {
    string a, b, c;
    in(a);
    in(b);
    in(c);

    int n = a.size();
    int m = b.size();
    int p = c.size();

    vector<vector<int>> hp(n + 1, vector<int>(m+1,-1));

    function<int(int, int)> func = [&](int ind, int ind2) -> int {
        if ((ind >= n && ind2 >= m)) {
            return 0;
        }
        if (hp[ind][ind2] != -1) return hp[ind][ind2];

        int ans = INT_MAX;

        if (ind < n) {
            int cost = (a[ind] != c[ind+ind2]) ? 1 : 0;
            ans = min(ans, func(ind + 1, ind2) + cost);
        }

        if (ind2 < m) {
            int cost = (b[ind2] != c[ind+ind2]) ? 1 : 0;
            ans = min(ans, func(ind, ind2 + 1) + cost);
        }

        return hp[ind][ind2] = ans;
    };

    int res = func(0, 0);
    out(res);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    in(t);
    while (t--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << endl
#define in(x) cin >> x
#define int long long

void solve() {
    string a, b, c;
    in(a);
    in(b);
    in(c);

    int n = a.size();
    int m = b.size();
    int p = c.size();

    vector<vector<vector<int>>> hp(n + 1, vector<vector<int>>(m + 1, vector<int>(p + 1, -1)));

    function<int(int, int, int)> func = [&](int ind, int ind2, int ind3) -> int {
        if ((ind >= n && ind2 >= m) || ind3 == p) {
            return 0;
        }
        if (hp[ind][ind2][ind3] != -1) return hp[ind][ind2][ind3];

        int ans = INT_MAX;

        if (ind < n) {
            int cost = (a[ind] != c[ind3]) ? 1 : 0;
            ans = min(ans, func(ind + 1, ind2, ind3 + 1) + cost);
        }

        if (ind2 < m) {
            int cost = (b[ind2] != c[ind3]) ? 1 : 0;
            ans = min(ans, func(ind, ind2 + 1, ind3 + 1) + cost);
        }

        return hp[ind][ind2][ind3] = ans;
    };

    int res = func(0, 0, 0);
    out(res);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    in(t);
    while (t--) {
        solve();
    }
}


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>
int hp[1005][1005];

int func(int ind,int ind2,string a,string b,string c){
    if(ind>=(a.size()) && ind2>=(b.size())){
        return 0;
    }
    if(hp[ind][ind2]!=-1) return hp[ind][ind2];
    int n = a.size();
    int ans=INT_MAX;
    if(ind<n){
    if(a[ind]==c[ind+ind2]){
        ans = min(ans,func(ind+1,ind2,a,b,c));
    }else{
        ans = min(ans,func(ind+1,ind2,a,b,c)+1);
    }
    }
    if(ind2<b.size()){
    if(b[ind2]==c[ind + ind2]){
        ans = min(ans,func(ind,ind2+1,a,b,c));
    }else{
        ans = min(ans,func(ind,ind2+1,a,b,c)+1);
    }
    }
    return hp[ind][ind2]=ans;
}

void solve(){
string a;
string b;
string c;
in(a);
in(b);
in(c);
memset(hp,-1,sizeof(hp));
int res = func(0,0,a,b,c);
out(res);

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    for i in range(1,n-1):
        if a[i]>a[i+1]:
            if a[i]-a[i-1]>a[i+1]:
                print('NO')
                break
    else:
        print('YES')

Submission (verdict: Wrong answer on test 2):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    else:
        for i in range(1,n-1):
            if a[i]>a[i+1]:
                if a[i-1]>a[i]:
                    print('NO')
                    break
                if a[i]-a[i-1]>a[i+1]:
                    print('NO')
                    break
        else:
            print('YES')
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    for i in range(1,n-1):
        if a[i]>a[i+1]:
            if a[i]-a[i-1]>a[i+1]:
                print('NO')
                break
    else:
        print('YES')
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    else:
        for i in range(1,n-1):
            if a[i]>a[i+1]:
                if a[i-1]>a[i]:
                    print('NO')
                    break
                if a[i]-a[i-1]>a[i+1]:
                    print('NO')
                    break
        else:
            print('YES')

Submission (verdict: Wrong answer on test 2):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    else:
        for i in range(1,n-1):
            if a[i]>a[i+1]:
                a[i]-=a[i-1]
            if a[i]>a[i+1]:
                print('NO')
                break
        else:
            print('YES')
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    else:
        for i in range(1,n-1):
            if a[i]>a[i+1]:
                a[i]-=a[i-1]
            if a[i]>a[i+1]:
                print('NO')
                break
        else:
            print('YES')

Submission (verdict: Accepted):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    if a[0]>a[1]:
        print('NO')
    else:
        for i in range(1,n-1):
            a[i]-=a[i-1]
            if a[i]>a[i+1]:
                print('NO')
                break
        else:
            print('YES')
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

map <vector<int>, bool> vis;
int n;
ll ret;
void bck(vector <int> ls, bool rev)
{
	if(vis[ls]) return;
	vis[ls] = 1;
	ll act = 0;
	for(auto u : ls) act += u;
	ret = max(ret, act);

	if((int)ls.size() == 1) return;
	vector <int> tmp;
	for(int i=1; i<(int)ls.size(); i++)
		tmp.push_back(ls[i]-ls[i-1]);
	bck(tmp,0);

	if(!rev)
	{
		reverse(ls.begin(), ls.end());
		bck(ls,1);
	}
}

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

	int t; cin >> t;
	while(t--)
	{
		cin >> n; vector <int> ls;
		for(int i=0; i<n; i++)
		{
			int a; cin >> a;
			ls.push_back(a);
		}
		vis.clear();
		ret = -1e9; bck(ls,0);
		cout << ret << '\n';
	}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

map <vector<ll>, bool> vis;
int n;
ll ret;
void bck(vector <ll> ls, bool rev)
{
	if(vis[ls]) return;
	vis[ls] = 1;
	ll act = 0;
	for(auto u : ls) act += u;
	ret = max(ret, act);

	if((int)ls.size() == 1) return;
	vector <ll> tmp;
	for(int i=1; i<(int)ls.size(); i++)
		tmp.push_back(ls[i]-ls[i-1]);
	bck(tmp,0);

	if(!rev)
	{
		reverse(ls.begin(), ls.end());
		bck(ls,1);
	}
}

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

	int t; cin >> t;
	while(t--)
	{
		cin >> n; vector <ll> ls;
		for(int i=0; i<n; i++)
		{
			ll a; cin >> a;
			ls.push_back(a);
		}
		vis.clear();
		ret = -1e18; bck(ls,0);
		cout << ret << '\n';
	}
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

#define ll long long

ll ret;
void bck(vector <int> ls, bool rev)
{
	ll act = 0;
	for(auto u : ls) act += u;
	ret = max(ret, act);

	if((int)ls.size() == 1) return;
	vector <int> tmp;
	for(int i=1; i<(int)ls.size(); i++)
		tmp.push_back(ls[i]-ls[i-1]);
	bck(tmp,0);

	if(!rev)
	{
		reverse(ls.begin(), ls.end());
		bck(ls,1);
	}
}

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

	int t; cin >> t;
	while(t--)
	{
		int n; cin >> n; vector <int> ls;
		for(int i=0; i<n; i++)
		{
			int a; cin >> a;
			ls.push_back(a);
		}
		ret = -1e9; bck(ls,0);
		cout << ret << '\n';
	}
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int n;
ll ret;
void bck(vector <int> ls, bool rev)
{
	ll act = 0;
	for(auto u : ls) act += u;
	ret = max(ret, act);
	
	if((int)ls.size() <= n-8) return;
	if((int)ls.size() == 1) return;
	vector <int> tmp;
	for(int i=1; i<(int)ls.size(); i++)
		tmp.push_back(ls[i]-ls[i-1]);
	bck(tmp,0);

	if(!rev)
	{
		reverse(ls.begin(), ls.end());
		bck(ls,1);
	}
}

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

	int t; cin >> t;
	while(t--)
	{
		cin >> n; vector <int> ls;
		for(int i=0; i<n; i++)
		{
			int a; cin >> a;
			ls.push_back(a);
		}
		ret = -1e9; bck(ls,0);
		cout << ret << '\n';
	}
}