ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        if(x>y)swap(x,y);
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m[{x,y}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice)ans--;
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>=choice) ans--;
        if(y==1)ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}


Submission (verdict: Wrong answer on test 9):
// time-limit: 3000
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    map<pair<int,int>,int> m2;
    for(auto i: m){
       int x = degree[i.first.first], y = degree[i.first.second];
       if(x>y)swap(x,y);
       m2[{x,y}]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m2[{y,x}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice) {
            ans--;
        }
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m2[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>=choice) ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        if(x>y)swap(x,y);
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m[{x,y}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>choice)ans--;
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>choice) ans--;
        if(y==1)ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}


Submission (verdict: Wrong answer on test 2):
// time-limit: 3000
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        if(x>y)swap(x,y);
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m[{x,y}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice)ans--;
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>=choice) ans--;
        if(y==1)ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    map<pair<int,int>,int> m2;
    for(auto i: m){
       int x = degree[i.first.first], y = degree[i.first.second];
       if(x>y)swap(x,y);
       m2[{x,y}]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m2[{y,x}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice) {
            ans--;
        }
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m2[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>=choice) ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}


Submission (verdict: Wrong answer on test 3):
// time-limit: 3000
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    map<pair<int,int>,int> m2;
    for(auto i: m){
       int x = degree[i.first.first], y = degree[i.first.second];
       if(x>y)swap(x,y);
       m2[{x,y}]++;
    }
    int idx = distance(degree.begin(),max_element(degree.begin(), degree.end()));
    vector<int> degree2 = degree;
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m2[{y,x}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice) {
            ans--;
        }
        cout<<ans<<"\n";
    }
    else {
        int ans = x + y -2;

        for(int i=0;i<n;i++){
            if(i==idx)continue;
            int res = degree2[i] + x -1 ;
            // cout<<i<<" "<<idx<<" "<<res<<"\n";
            if(m.find({min(i,idx),max(i,idx)})!=m.end()){
                res--;
            } 
            ans=max(ans,res);
        }
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}
Problem: 2052A - Adrenaline Rush
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    que=[]
    res=[]
    for i in range(n-1,-1,-1):
        for j in range(len(que)-1,-1,-1):
            res.append((a[i],que[j]))
        que.insert(0,a[i])
        for j in range(a[i]-1,0,-1):
            if j not in que:
                res.append((a[i],j))

    print(len(res))
    for el in res:
        print(*el)
solve()


Submission (verdict: Time limit exceeded on test 42):
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    que=[]
    res=[]
    for i in range(n-1,-1,-1):
        for j in range(a[i]-1,0,-1):
            if j not in que:
                res.append((a[i],j))
        for j in range(len(que)-1,-1,-1):
            res.append((a[i],que[j]))
        que.insert(0,a[i])

    print(len(res))
    for el in res:
        print(*el)
solve()
Problem: 2052A - Adrenaline Rush
Language: Python 3


Submission (verdict: Wrong answer on test 1):
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    que=[]
    res=[]
    for i in range(n-1,-1,-1):
        for j in range(len(que)-1,-1,-1):
            res.append((a[i],que[j]))
        que.insert(0,a[i])
        for j in range(a[i]-1,0,-1):
            if j not in que:
                res.append((a[i],j))

    print(len(res))
    for el in res:
        print(*el)
solve()
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 42):
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    que=[]
    res=[]
    for i in range(n-1,-1,-1):
        for j in range(a[i]-1,0,-1):
            if j not in que:
                res.append((a[i],j))
        for j in range(len(que)-1,-1,-1):
            res.append((a[i],que[j]))
        que.insert(0,a[i])

    print(len(res))
    for el in res:
        print(*el)
solve()


Submission (verdict: Accepted):
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    que=[]
    res=[]
    for i in range(n-1,-1,-1):
        for j in range(a[i]-1,0,-1):
            if j not in que:
                res.append((a[i],j))
        for j in range(len(que)-1,-1,-1):
            res.append((a[i],que[j]))
        que.insert(0,a[i])

    print(len(res))
    for el in res:
        print(*el)
solve()
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int &i:a) 
    {
        cin >> i;
        sum += i;
    }
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i)
    {
        for(int j=0;j<a.size()-1;++j)
            a[j]=a[j+1]-a[j];
        a.pop_back();
        int temp = 0;
        for(int j=0;j<a.size();++j)
            temp+=a[j];
        if(abs(temp)>abs(sum) )
        {
            sum=temp;
        }
    }
    cout<<abs(sum)<<endl;
}

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


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    long long int sum = 0;
    for(int &i:a) 
    {
        cin >> i;
        sum += i;
    }
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i)
    {
        for(int j=0;j<a.size()-1;++j)
            a[j]=a[j+1]-a[j];
        a.pop_back();
        long long int temp = 0;
        for(int j=0;j<a.size();++j)
            temp+=a[j];
        if(abs(temp)>abs(sum) )
        {
            sum=temp;
        }
    }
    cout<<abs(sum)<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    long long int sum = 0;
    for(int &i:a) 
    {
        cin >> i;
        sum += i;
    }
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i)
    {
        for(int j=0;j<a.size()-1;++j)
            a[j]=a[j+1]-a[j];
        a.pop_back();
        long long int temp = 0;
        for(int j=0;j<a.size();++j)
            temp+=a[j];
        if(abs(temp)>abs(sum) )
        {
            sum=temp;
        }
    }
    cout<<abs(sum)<<endl;
}

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


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
	long long a[1010];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int now = n;
	long long ans = -1e18;
	for (int i = 1; i <= n; i++) {
		long long sum = 0;
		for (int i = 1; i <= now; i++) sum = (sum + a[i]);
		if (i == 1) ans = max(ans, sum);
		else ans = max(ans, max(sum, (-sum)));
		for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]);
		now--;
	}
	cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int &i:a) 
    {
        cin >> i;
        sum += i;
    }
    if (n == 1)
    {
        cout << a[0] << endl;
        return;
    }
    for (int i = 0; i < n - 1; ++i)
    {
        for(int j=0;j<a.size()-1;++j)
            a[j]=a[j+1]-a[j];
        a.pop_back();
        int temp = 0;
        for(int j=0;j<a.size();++j)
            temp+=a[j];
        if(abs(temp)>abs(sum) )
        {
            sum=temp;
        }
    }
    cout<<abs(sum)<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int n;
	cin >> n;
	vector<vector<int> > e(n);
	vector<int> cnt(n,0);
	for(int i=0;i<=n-2;i++){
		int u,v;
		cin >> u >> v;
		e[u-1].push_back(v-1);
		e[v-1].push_back(u-1);
		cnt[u-1]++;
		cnt[v-1]++;
	}
	int mx=0,mxnode;
	for(int i=0;i<n;i++){
		if(cnt[i]>mx){
			mx=cnt[i];
			mxnode=i;
		}
	}
	int re=mx;
	mx=-1;
	int secnode;
	for(int i=0;i<e[mxnode].size();i++){
		cnt[e[mxnode][i]]-=1;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]>mx&&i!=mxnode){
			mx=cnt[i];
			secnode=i;
		}
	}
//	cout << secnode << '\n';
	re += (mx-1);
	cout << re << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

    return 0;
}


Submission (verdict: Accepted):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int n;
	cin >> n;
	vector<vector<int> > e(n);
	vector<int> cnt(n,0);
	for(int i=0;i<=n-2;i++){
		int u,v;
		cin >> u >> v;
		e[u-1].push_back(v-1);
		e[v-1].push_back(u-1);
		cnt[u-1]++;
		cnt[v-1]++;
	}
	int mx=0,mxnode;
	int bigcnt=0;
	for(int i=0;i<n;i++){
		if(cnt[i]>=mx){
			mx=cnt[i];
			mxnode=i;
		}
	}
	for(int i=0;i<n;i++){
		if(cnt[i] == mx){
			bigcnt++;
		}
	}
	if(bigcnt>2){
		cout << mx*2-1 << '\n';
		return;
	}
	int re=mx;
	mx=-1;
	int secnode;
	for(int i=0;i<e[mxnode].size();i++){
		cnt[e[mxnode][i]]-=1;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]>mx&&i!=mxnode){
			mx=cnt[i];
			secnode=i;
		}
	}
//	cout << secnode << '\n';
	re += (mx-1);
	cout << re << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int n;
	cin >> n;
	vector<vector<int> > e(n);
	vector<int> cnt(n,0);
	for(int i=0;i<=n-2;i++){
		int u,v;
		cin >> u >> v;
		e[u-1].push_back(v-1);
		e[v-1].push_back(u-1);
		cnt[u-1]++;
		cnt[v-1]++;
	}
	int mx=0,mxnode;
	for(int i=0;i<n;i++){
		if(cnt[i]>mx){
			mx=cnt[i];
			mxnode=i;
		}
	}
	int re=0;
	re=mx;
	mx=-1;
	int secnode;
	for(int i=0;i<e[mxnode].size();i++){
		cnt[e[mxnode][i]]-=1;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]>mx&&i!=mxnode){
			mx=cnt[i];
			secnode=i;
		}
	}
//	cout << secnode << '\n';
	re += cnt[secnode]-1;
	cout << re << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

    return 0;
}


Submission (verdict: Wrong answer on test 2):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int n;
	cin >> n;
	vector<vector<int> > e(n);
	vector<int> cnt(n,0);
	for(int i=0;i<=n-2;i++){
		int u,v;
		cin >> u >> v;
		e[u-1].push_back(v-1);
		e[v-1].push_back(u-1);
		cnt[u-1]++;
		cnt[v-1]++;
	}
	int mx=0,mxnode;
	for(int i=0;i<n;i++){
		if(cnt[i]>mx){
			mx=cnt[i];
			mxnode=i;
		}
	}
	int re=mx;
	mx=-1;
	int secnode;
	for(int i=0;i<e[mxnode].size();i++){
		cnt[e[mxnode][i]]-=1;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]>mx&&i!=mxnode){
			mx=cnt[i];
			secnode=i;
		}
	}
//	cout << secnode << '\n';
	re += (mx-1);
	cout << re << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
//#include <iomanip>
#include<complex>
#include<bits/stdc++.h>


#include<cmath>
#define INF 1000000005
#define PI M_PI


using namespace std;

void fun() {
	int n;
	cin >> n;
	vector<vector<int> > e(n);
	vector<int> cnt(n,0);
	for(int i=0;i<=n-2;i++){
		int u,v;
		cin >> u >> v;
		e[u-1].push_back(v-1);
		e[v-1].push_back(u-1);
		cnt[u-1]++;
		cnt[v-1]++;
	}
	int mx=0,mxnode;
	for(int i=0;i<n;i++){
		if(cnt[i]>mx){
			mx=cnt[i];
			mxnode=i;
		}
	}
	int re=0;
	re=mx;
	mx=-1;
	int secnode;
	for(int i=0;i<e[mxnode].size();i++){
		cnt[e[mxnode][i]]-=1;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]>mx&&i!=mxnode){
			mx=cnt[i];
			secnode=i;
		}
	}
//	cout << secnode << '\n';
	re += cnt[secnode]-1;
	cout << re << '\n';
}

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

    int T = 1;
	cin >> T;
//	getchar();
    while (T--) fun();

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


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

typedef long long ll;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(2 * n);
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        a[i] = ai;
        a[i + n] = ai;
    }
    ll sliding = a[0];
    ll best_sofar = LLONG_MAX;
    int size = r - l + 1;
    int j = 0;
    for (int i = 1; i < 2 * n; i++) {
        if(i - j == size){
            sliding -= a[j]; 
            j += 1;
        }
        sliding += a[i];
        if(i - j + 1 == size){
            best_sofar = min(sliding, best_sofar); 
        }
    }

    cout << best_sofar << endl;
}

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

    int t = 1;
    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 <bits/stdc++.h>
using namespace std;

typedef long long ll;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(2 * n);
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        a[i] = ai;
        a[i + n] = ai;
    }
    ll sliding = a[0];
    ll best_sofar = LLONG_MAX;
    int size = r - l + 1;
    int j = 0;
    for (int i = 1; i < 2 * n; i++) {
        if(i - j == size){
            sliding -= a[j]; 
            j += 1;
        }
        sliding += a[i];
        if(i - j + 1 == size){
            best_sofar = min(sliding, best_sofar); 
        }
    }

    cout << best_sofar << endl;
}

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

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}


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

typedef long long ll;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(2 * n);
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        a[i] = ai;
        a[i + n] = ai;
    }
    ll best = 0;
    int size = r - l + 1;
    for (int i = 0; i < size; i++) {
        best += a[i];
    }
    ll curr = best;
    for (int i = size; i < 2 * n; i++) {
        curr -= a[i - size];
        curr += a[i];
        best = min(curr, best);
    }
    cout << best << endl;
}

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

    int t = 1;
    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 <bits/stdc++.h>
using namespace std;

typedef long long ll;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(2 * n);
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        a[i] = ai;
        a[i + n] = ai;
    }
    ll best = 0;
    int size = r - l + 1;
    for (int i = 0; i < size; i++) {
        best += a[i];
    }
    ll curr = best;
    for (int i = size; i < 2 * n; i++) {
        curr -= a[i - size];
        curr += a[i];
        best = min(curr, best);
    }
    cout << best << endl;
}

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

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}


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

typedef long long ll;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    for (auto& ai : a)
        cin >> ai;
    sort(a.begin(), a.end());
    int size = r - l + 1;
    cout << accumulate(a.begin(), a.begin() + size, 0ll) << endl;
}

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

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}