ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: Python 3

Previous submission (verdict: Wrong answer on test 2):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    a = list(map(int,input().split()))

    l -= 1

    r -= 1



    

    in1 = a[l:r+1]  

    out2 = a[:l] + a[r+1:]



   

    in1.sort(reverse=True)

    

    

    out2.sort()



    

    for i in range(min(len(in1), len(out2))):

        if out2[i] < in1[i]:

            in1[i] = out2[i]

        else:

            break 



    

    print(sum(in1))

        

    

Submission (verdict: Accepted):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    arr = list(map(int,input().split()))

   



    l-=1

    brr=arr[:l]+sorted(arr[l:])

    crr=sorted(arr[:r])[::-1]+arr[r:]

    print(min(sum(brr[l:r]),sum(crr[l:r])))
Problem: 2063B - Subsequence Update
Language: Python 3


Submission (verdict: Wrong answer on test 2):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    arr = list(map(int,input().split()))

    arr.sort()

    sum = 0

    ln = r - l

    cu = 0

    while cu <= ln:

        sum+=arr[cu]

        cu+=1

    print(sum)
Problem: 2063B - Subsequence Update
Language: Python 3

Previous submission (verdict: Wrong answer on test 2):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    arr = list(map(int,input().split()))

    arr.sort()

    sum = 0

    ln = r - l

    cu = 0

    while cu <= ln:

        sum+=arr[cu]

        cu+=1

    print(sum)

        

    

Submission (verdict: Wrong answer on test 2):
t = int(input())

for _ in range(t):

    n,l,r = map(int,input().split())

    a = list(map(int,input().split()))

    l -= 1

    r -= 1



    

    in1 = a[l:r+1]  

    out2 = a[:l] + a[r+1:]



   

    in1.sort(reverse=True)

    

    

    out2.sort()



    

    for i in range(min(len(in1), len(out2))):

        if out2[i] < in1[i]:

            in1[i] = out2[i]

        else:

            break 



    

    print(sum(in1))
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<min(i + 10, s.size()); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) swap(s[mxid-1], s[mxid]), -- mxid;

s[i] = char(mx + 48);

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*       . .

1709 -> 6109 -> 6701 ???

z < 10

1709 -> 6109 -> 6180 -> 6710

*/

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

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<min(i + 10, (int)s.size()); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) swap(s[mxid-1], s[mxid]), -- mxid;

s[i] = char(mx + 48);

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*       . .

1709 -> 6109 -> 6701 ???

z < 10

1709 -> 6109 -> 6180 -> 6710

*/
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<s.size(); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) --s[mxid], swap(s[mxid-1], s[mxid]), -- mxid;

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*

6190

*/

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

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<s.size(); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) swap(s[mxid-1], s[mxid]), -- mxid;

s[i] = mx;

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*

6190

*/
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<s.size(); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) swap(s[mxid-1], s[mxid]), -- mxid;

s[i] = mx;

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*

6190

*/

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

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<min(i + 10, s.size()); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) swap(s[mxid-1], s[mxid]), -- mxid;

s[i] = char(mx + 48);

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*       . .

1709 -> 6109 -> 6701 ???

z < 10

1709 -> 6109 -> 6180 -> 6710

*/
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {

string s; cin>>s;

for(int i = 0; i<s.size(); ++i){

int mx = s[i] - 48, mxid = -1;

for(int j = i+1; j<s.size(); ++ j){

if(mx < s[j] - 48 - j + i){

mx = s[j] - 48 - j + i;

mxid = j;

}

}

while(mxid > i) --s[mxid], swap(s[mxid-1], s[mxid]), -- mxid;

}

cout<<s;

}

signed main() {

cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

cin >> t;

while (t--) {

solve();

cout << '\n';

}

}

/*

6190

*/
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 5, mod = 1e9 + 7;
const long long inf = 1e18;
#define pb push_back
#define all(c) c.begin(), c.end()
#define allr(a) a.rbegin(),a.rend()
#define debug(x) cout << '>' << #x << " : " << x << endl;
#define F first
#define S second
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef unsigned long long ull;
typedef long long ll;

/*
  // think greedy first, codeforces A,B usually some sort of greedy, A super simple usually (800)
  // C on Div2 or E on Div3/4 require more thinking but still not too hard
  // for later problems, think about data structures like segment tree and ordered set
  // try query problems, im oddly good at them
  // As a participant, I approve these statements.
*/

void file_input() {
  freopen(".in","r",stdin);
  freopen(".out","w",stdout);
}


void solve(){
    ll t=1;   cin>>t;
    while(t--){
        ll x, y;    cin>>x>>y;
        ll c=0;
        bool f=0;
        
        for(ll i=30 ; i>=0 ; i--){
            ll bit_x= ((x>>i) & 1);
            ll bit_y= ((y>>i) & 1);
            //cout << "Bit position: " << i << ", x: " << bit_x << ", y: " << bit_y << endl;
            if(bit_x!=bit_y and f==0){
                f=1;
            }
            else if(f){
                if(bit_y==0) c= c | (1<<i);
                ll bit_c= ((c>>i) & 1);
                //debug(bit_c);
            }
        }

        if(c<=x){
            c= x+1;

        }
        if(c>=y){
            c=y-1;
        }

        cout<<x<<' '<<y<<' '<<c<<endl;
    }
}

int main()
{
    //file_input();
    fastIO;
    solve();
}
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
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n, mx = 0; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}


Submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n, mx = 0; cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	// cin >> t;
	while (t--) Solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n, mx = 0; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}
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
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n; cin >> n;
	ll mx = 0;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
ll sum(vector<ll> a) {
	ll ret = 0;
	for (int i = 0; i < a.size(); ++i) {
		ret += a[i];
	}
	 return ret;
}
void Solve() {
	int n; cin >> n;
	ll mx = 0;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
		mx = max(mx, abs(sum(v)));
	}
	cout << mx << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n, mx = 0; cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	// cin >> t;
	while (t--) Solve();
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n; cin >> n;
	ll mx = 0;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		mx += v[i];
	}
	if (n == 1) {
		return void(cout << v.front() << "\n");
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < v.size() - 1; ++j) {
			v[j] = v[j + 1] - v[j];
		}
		v.pop_back();
	}
	cout << max(mx, abs(v.front())) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

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

    int n, t, ans, u, v, cnt;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        ans = 0;
        cin >> n;
        multiset<int> s, tmp;
        vector<int> deg(n, 0), first;
        vector<vector<int>> adjList(n);

        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;

            adjList[u].push_back(v);
            adjList[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        for (auto d : deg)
            s.insert(d);

        for (int u = 0; u < n; u++)
        {
            tmp = s;

            auto itr = tmp.find(deg[u]);
            tmp.erase(itr);

            cnt = (deg[u] - 1);

            for (auto v : adjList[u])
            {
                auto itr = tmp.find(deg[v]);
                tmp.erase(itr);
                tmp.insert(deg[v] - 1);
            }

            cnt += *prev(tmp.end());
            ans = max(cnt, ans);
        }

        cout << ans << "\n";
    }

    return 0;
}


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

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

    int n, t, ans, u, v, cnt;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        ans = 0;
        cin >> n;
        multiset<int> s;
        vector<int> deg(n, 0);
        vector<vector<int>> adjList(n);

        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;

            adjList[u].push_back(v);
            adjList[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        for (auto d : deg)
            s.insert(d);

        for (int u = 0; u < n; u++)
        {
            auto itr = s.find(deg[u]);
            s.erase(itr);

            cnt = (deg[u] - 1);

            for (auto v : adjList[u])
            {
                itr = s.find(deg[v]);
                s.erase(itr);
                s.insert(deg[v] - 1);
            }

            cnt += *prev(s.end());
            ans = max(cnt, ans);

            s.insert(deg[u]);
            for (auto v : adjList[u])
            {

                itr = s.find(deg[v] - 1);
                s.erase(itr);
                s.insert(deg[v]);
            }
        }

        cout << ans << "\n";
    }

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


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

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

    int n, t, ans, u, v, cnt;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        ans = 0;
        cin >> n;
        multiset<int> s, tmp;
        vector<int> deg(n, 0), first;
        vector<vector<int>> adjList(n);

        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;

            adjList[u].push_back(v);
            adjList[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        for (auto d : deg)
            s.insert(d);

        for (int u = 0; u < n; u++)
        {
            tmp = s;
            cnt = (deg[u] - 1);
            tmp.erase(deg[u]);

            for (auto v : adjList[u])
            {
                tmp.erase(deg[v]);
                tmp.insert(deg[v] - 1);
            }

            cnt += *prev(tmp.end());
            ans = max(cnt, ans);
        }

        cout << ans << "\n";
    }

    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 int

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

    int n, t, ans, u, v, cnt;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        ans = 0;
        cin >> n;
        multiset<int> s, tmp;
        vector<int> deg(n, 0), first;
        vector<vector<int>> adjList(n);

        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;

            adjList[u].push_back(v);
            adjList[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        for (auto d : deg)
            s.insert(d);

        for (int u = 0; u < n; u++)
        {
            tmp = s;
            cnt = (deg[u] - 1);
            tmp.erase(deg[u]);

            for (auto v : adjList[u])
            {
                tmp.erase(deg[v]);
                tmp.insert(deg[v] - 1);
            }

            cnt += *prev(tmp.end());
            ans = max(cnt, ans);
        }

        cout << ans << "\n";
    }

    return 0;
}


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

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

    int n, t, ans, u, v, cnt;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        ans = 0;
        cin >> n;
        multiset<int> s, tmp;
        vector<int> deg(n, 0), first;
        vector<vector<int>> adjList(n);

        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;

            adjList[u].push_back(v);
            adjList[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        for (auto d : deg)
            s.insert(d);

        for (int u = 0; u < n; u++)
        {
            tmp = s;

            auto itr = tmp.find(deg[u]);
            tmp.erase(itr);

            cnt = (deg[u] - 1);

            for (auto v : adjList[u])
            {
                auto itr = tmp.find(deg[v]);
                tmp.erase(itr);
                tmp.insert(deg[v] - 1);
            }

            cnt += *prev(tmp.end());
            ans = max(cnt, ans);
        }

        cout << ans << "\n";
    }

    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define ll long long

using namespace std;



int main(){

    int t;

    cin>>t;



    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> arrleft(n);

        vector<int> arrright(n);

        for(int i=0; i<n; i++){

            int x;

            cin>>x;

            arrleft[i] =x; arrright[i]=x;

        }



        sort(arrleft.begin(), arrleft.end());

        sort(arrright.begin(), arrright.end());



        ll total1=0, total2=0;

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

            total1 += arrleft[i];

            total2 += arrright[i];

        }



        cout<<min(total1, total2)<<endl;

    }

}



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

#define ll long long

using namespace std;



int main(){

    int t;

    cin>>t;



    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        l--; r--;

        vector<int> arrleft;     //[left, n-1]

        vector<int> arrright;    //[0, right]

        for(int i=0; i<n; i++){

            int x; cin>>x;

            if(i>=l && i<=n-1) arrleft.push_back(x);

            if(i>=0 && i<=r) arrright.push_back(x);

        }



        sort(arrleft.begin(), arrleft.end());

        sort(arrright.begin(), arrright.end());



        ll total1=0, total2=0;

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

            total1 += arrleft[i];

            total2 += arrright[i];

        }



        cout<<min(total1, total2)<<endl;

    }

}