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

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

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> indeg(n + 1, 0);
    for (int i = 0; i < n - 1; i++) {
        int src, des;
        cin >> src >> des;
        adj[src].push_back(des);
        adj[des].push_back(src);
        indeg[src]++;
        indeg[des]++;
    }
    int maxi = -1, max_edges = -1;
    for (int i = 1; i <= n; i++) {
        if (indeg[i] > max_edges) {
            max_edges = indeg[i];
            maxi = i;
        }
    }
    if (max_edges == 1) {
        cout << max(0, n - 2) << endl;
        return;
    }
    unordered_set<int> st;
    for (int node : adj[maxi]) {
        st.insert(node);
        indeg[node]--;
    }
    indeg[maxi] = 0;
    int maxi2 = -1, max_edges2 = -1;
    for (int i = 1; i <= n; i++) {
        if (indeg[i] > max_edges2 && !st.count(i)) {
            max_edges2 = indeg[i];
            maxi2 = i;
        }
    }
    cout << (max_edges + max_edges2 - 1) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T;
    cin >> T;
    while (T--) solve();
}


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

void solve() {
    int n;
    cin >> n;
    vector<unordered_set<int>> adj(n + 1);
    map<int, int, less<int>> indeg; 
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);adj[v].insert(u);
        indeg[u]++; indeg[v]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (auto &[node, degree] : indeg) {
            if(node==i) continue;
            else if (adj[i].count(node) ) { 
                ans = max(ans, indeg[node] + indeg[i] - 2);
            } else { 
                ans = max(ans, indeg[node] + indeg[i] - 1);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) solve();
}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

        for(i=0;i<n-1;i++){

            if(s[i]=='p'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='s'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(i>0 && i<n-2 && s[i]=='s'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='p'){

                        ok=0;

                        break;

                    }

                }

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

        for(i=0;i<n-1;i++){

            if(s[i]=='p'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='s'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(i>0 && i<n-2 && s[i]=='s'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='p'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

        for(i=0;i<n-1;i++){

            if(s[i]=='p'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='s'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(i>0 && i<n-2 && s[i]=='s'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='p'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

        if(s[0]=='s')   s[0]='.';

        if(s[n-1]=='p')   s[n-1]='.';

        for(i=0;i<n-1;i++){

            if(s[i]=='p'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='s'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(s[i]=='s'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='p'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,i,j,ok=1;

        cin>>n;

        string s;

        cin>>s;

        for(i=0;i<n-1;i++){

            if(s[i]=='p'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='s'){

                        ok=0;

                        break;

                    }

                }

                if(ok==0)   break;

            }

            if(i>0 && i<n-2 && s[i]=='s'){

                for(j=i+1;j<n;j++){

                    if(s[j]=='p'){

                        ok=0;

                        break;

                    }

                }

            }

        }

        if(ok==1)   cout<<"YES\n";

        else cout<<"NO\n";

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>

#include<algorithm>

#include<vector>

#define ll long long

#define endl '\n'





using namespace std;



const int N = 1e5 + 5;

int a[N];



void solve()

{

	int n,l,r;

	ll ans = 0;

	cin>>n>>l>>r;

	for(int i = 1 ;i <= n ; i ++)

	{

		cin>>a[i];

	}

	sort(a + 1, a + 1 + n);

	for(int i = 1 ;i <= r - l + 1; i ++)

	ans += a[i];

	cout << ans << endl;

	for(int i = 1;i <= n; i++)

	a[i] = 0;

}



int main()

{

	ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Submission (verdict: Accepted):
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
#define endl '\n'


using namespace std;

const int N = 1e5 + 5;
int a[N];
int b[N];

void solve()
{
	int n,l,r;
	ll ans = 0;
	ll mi = 0;
	cin>>n>>l>>r;
	for(int i = 1 ;i <= n ; i ++)
	{
		cin>>a[i];
		b[i] = a[i];
	}
	sort(b + 1,b + r + 1);
	for(int i = 1 ;i <= r - l + 1; i ++)
		mi += b[i];
	for(int i = 1;i <= n;i++)
		b[i] = a[i];
	sort(b + l,b + n + 1);
	for(int i = l; i <= r;i ++)
		ans += b[i];
	cout << min(ans,mi) << endl;
	for(int i = 1;i <= n; i++)
	{
		a[i] = 0;
		b[i] = 0;
	}
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>

#include<algorithm>

#include<vector>

#define ll long long

#define endl '\n'





using namespace std;



const int N = 1e5 + 5;

int a[N];



void solve()

{

	int n,l,r;

	ll ans = 0;

	cin>>n>>l>>r;

	for(int i = 1 ;i <= n ; i ++)

	{

		cin>>a[i];

	}

	sort(a + 1, a + 1 + n);

	for(int i = 1 ;i <= r - l + 1; i ++)

	ans += a[i];

	cout << ans << endl;

}



int main()

{

	ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include<iostream>

#include<algorithm>

#include<vector>

#define ll long long

#define endl '\n'





using namespace std;



const int N = 1e5 + 5;

int a[N];



void solve()

{

	int n,l,r;

	ll ans = 0;

	cin>>n>>l>>r;

	for(int i = 1 ;i <= n ; i ++)

	{

		cin>>a[i];

	}

	sort(a + 1, a + 1 + n);

	for(int i = 1 ;i <= r - l + 1; i ++)

	ans += a[i];

	cout << ans << endl;

	for(int i = 1;i <= n; i++)

	a[i] = 0;

}



int main()

{

	ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<iostream>

#include<algorithm>

#include<vector>

#define ll long long

#define endl '\n'





using namespace std;



const int N = 1e5 + 5;

int a[N];



void solve()

{

	int n,l,r;

	ll ans = 0;

	cin>>n>>l>>r;

	for(int i = 1 ;i <= n ; i ++)

	{

		cin>>a[i];

	}

	sort(a + 1, a + 1 + n);

	for(int i = 1 ;i <= r - l + 1; i ++)

	ans += a[i];

	cout << ans << endl;

}



int main()

{

	ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0;

}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int vis[N];
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		memset(du,0,sizeof du);
		memset(vis,0,sizeof vis);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
			}
		}
		vector<int>m1;
		for(int i=1;i<n;i++)
		{
			if(g[i].size()==ans1)
			{
				m1.push_back(i);
				vis[i]=1;
			}
		}
		for(auto x:m1)
		{
			int tmp=0;
			for(auto i:g[x])
			{
				tmp+=vis[i];
			}
			if(tmp<=1)
			{
				v1=x;
				break;
			}
		}
		du[v1]=0;
		ans1=g[v1].size();
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2)
			{
				ans2=du[i];
				v2=i;
			}
			g[i].clear();
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int vis[N];
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		memset(du,0,sizeof du);
		memset(vis,0,sizeof vis);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
			}
		}
		vector<int>m1;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()==ans1)
			{
				m1.push_back(i);
				vis[i]=1;
			}
		}
		for(auto x:m1)
		{
			int tmp=0;
			for(auto i:g[x])
			{
				tmp+=vis[i];
			}
			if(tmp<=1)
			{
				v1=x;
				break;
			}
		}
		du[v1]=0;
		ans1=g[v1].size();
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2)
			{
				ans2=du[i];
			}
			g[i].clear();
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		for(int i=1;i<=n;i++) g[i].clear();
		memset(du,0,sizeof du);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
				v1=i;
//				cout<<i<<"->"<<g[i].size()<<"->"<<" ";
			}
		}
		du[v1]=0;
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2 && i!=v1)
			{
				ans2=du[i];
				v2=i;
			}
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		memset(du,0,sizeof du);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
				v1=i;
//				cout<<i<<"->"<<g[i].size()<<"->"<<" ";
			}
		}
		du[v1]=0;
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2 && i!=v1)
			{
				ans2=du[i];
				v2=i;
			}
			g[i].clear();
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		for(int i=1;i<=n;i++) g[i].clear();
		memset(du,0,sizeof du);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
				v1=i;
//				cout<<i<<"->"<<g[i].size()<<"->"<<" ";
			}
		}
		du[v1]=0;
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2 && i!=v1)
			{
				ans2=du[i];
				v2=i;
			}
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		memset(du,0,sizeof du);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
				v1=i;
//				cout<<i<<"->"<<g[i].size()<<"->"<<" ";
			}
		}
		du[v1]=0;
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2 && i!=v1)
			{
				ans2=du[i];
				v2=i;
			}
			g[i].clear();
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+5;
vector<int>g[N];
int du[N];
int read()
{
	int t=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return t*x;
}
int ans1,ans2;
int vis[N];
int v1,v2;
signed main()
{
	int t=read();
	int n;
	while(t--)
	{
		memset(du,0,sizeof du);
		memset(vis,0,sizeof vis);
		n=read();
		for(int i=1;i<n;i++)
		{
			int u=read();
			int v=read();
			g[u].push_back(v);
			g[v].push_back(u);
			du[u]++;
			du[v]++;
		}
		v1=v2=ans1=ans2=0;
		for(int i=1;i<=n;i++)
		{
			if(g[i].size()>ans1)
			{
				ans1=g[i].size();
			}
		}
		vector<int>m1;
		for(int i=1;i<n;i++)
		{
			if(g[i].size()==ans1)
			{
				m1.push_back(i);
				vis[i]=1;
			}
		}
		for(auto x:m1)
		{
			int tmp=0;
			for(auto i:g[x])
			{
				tmp+=vis[i];
			}
			if(tmp<=1)
			{
				v1=x;
				break;
			}
		}
		du[v1]=0;
		ans1=g[v1].size();
		for(auto tmp:g[v1])
		{
			du[tmp]--;
		}
		for(int i=1;i<=n;i++)
		{
			if(du[i]>ans2)
			{
				ans2=du[i];
				v2=i;
			}
			g[i].clear();
		}
		printf("%lld\n",ans1+ans2-1);
	}
	
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: Java 8


Submission (verdict: Time limit exceeded on test 2):
import java.math.BigInteger;
import java.util.*;

public class Cirno {
    static Scanner sc = new Scanner(System.in);

    static BigInteger bsum = BigInteger.valueOf(Integer.MIN_VALUE);

    static void diffFinder(int arr[], int r) {
        BigInteger sum = BigInteger.ZERO;

        for (int i = 0; i < r; i++) {
            sum = sum.add(BigInteger.valueOf(arr[i]));
        }

        if (sum.compareTo(bsum) > 0) {
            bsum = sum;
        }

        if (r <= 1)
            return;
        else {
            int sys[] = new int[r - 1];
            int revsys[] = new int[r - 1];

            for (int i = 0; i < r - 1; i++) {
                sys[i] = arr[i + 1] - arr[i];
            }

            for (int i = r - 1, j = 0; i > 0 && j < r - 1; i--, j++) {
                revsys[j] = arr[i - 1] - arr[i];
            }
            diffFinder(sys, r - 1);
            diffFinder(revsys, r - 1);
        }
    }

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            diffFinder(arr, n);
            System.out.println(bsum);
        }
    }
}
Problem: 2062C - Cirno and Operations
Language: Java 8

Previous submission (verdict: Time limit exceeded on test 2):
import java.math.BigInteger;
import java.util.*;

public class Cirno {
    static Scanner sc = new Scanner(System.in);

    static BigInteger bsum = BigInteger.valueOf(Integer.MIN_VALUE);

    static void diffFinder(int arr[], int r) {
        BigInteger sum = BigInteger.ZERO;

        for (int i = 0; i < r; i++) {
            sum = sum.add(BigInteger.valueOf(arr[i]));
        }

        if (sum.compareTo(bsum) > 0) {
            bsum = sum;
        }

        if (r <= 1)
            return;
        else {
            int sys[] = new int[r - 1];
            int revsys[] = new int[r - 1];

            for (int i = 0; i < r - 1; i++) {
                sys[i] = arr[i + 1] - arr[i];
            }

            for (int i = r - 1, j = 0; i > 0 && j < r - 1; i--, j++) {
                revsys[j] = arr[i - 1] - arr[i];
            }
            diffFinder(sys, r - 1);
            diffFinder(revsys, r - 1);
        }
    }

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            diffFinder(arr, n);
            System.out.println(bsum);
        }
    }
}


Submission (verdict: Wrong answer on test 2):
import java.math.BigInteger;
import java.util.*;

public class Cirno {
    static Scanner sc = new Scanner(System.in);

    static BigInteger bsum = BigInteger.valueOf(Integer.MIN_VALUE);

    static void diffFinder(BigInteger arr[]) {
        BigInteger sum = BigInteger.ZERO;

        for (int i = 0; i < arr.length; i++) {
            sum = sum.add(arr[i]);
        }
        sum = sum.abs();
        if (sum.compareTo(bsum) > 0) {
            bsum = sum;
        }

        if (arr.length <= 1)
            return;
        else {
            BigInteger sys[] = new BigInteger[arr.length - 1];

            for (int i = 0; i < arr.length - 1; i++) {
                sys[i] = arr[i + 1].subtract(arr[i]);
            }

            diffFinder(sys);
        }
    }

    public static void main(String[] args) {
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            BigInteger arr[] = new BigInteger[n];
            for (int i = 0; i < n; i++) {
                arr[i] = BigInteger.valueOf(sc.nextInt());
            }
            if (n == 1) {
                System.out.println(arr[0]);
            } else {
                diffFinder(arr);
                System.out.println(bsum);
                bsum = BigInteger.valueOf(Integer.MIN_VALUE);
            }
        }
    }
}