ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
#pragma region usual_defs
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

// this is the only reason I like C++ (sorry, java, try to be more fun next time):
#define meow cin
#define murr cout
#define lol long long
#define lmao unsigned long long
#define el '\n'
#define none \
    {        \
    }
#define kaput return
#define kill break
#define nah continue
using namespace std;
#pragma endregion usual_defs
// #define SYNC
#define i_like_cats
// WHY AM I SO DUMBBBBB
int s[200000];
char ch;
int n, j, t;
void cat()
{
    n = 0;
    while (true)
    {
        meow.get(ch);
        if (ch == '\n')
            kill;
        s[n++] = ch - '0';
    }
    for (int i = 1; i < n; i++)
    {
        j = i;
        while (j > 0 && s[j - 1] < s[j] - 1)
        {
            t = s[j - 1];
            s[j - 1] = s[j] - 1;
            s[j--] = t;
        }
    }
    for (int i = 0; i < n; i++)
        murr << s[i];
    murr << el;
}

#pragma region main
#ifdef i_like_cats
int INPUT_SETS_COUNT;
#endif
int main()
{
    ios_base::sync_with_stdio(false);
#ifndef SYNC
    meow.tie(NULL);
#endif
#ifdef i_like_cats
    meow >> INPUT_SETS_COUNT;
    meow.ignore();
    while (INPUT_SETS_COUNT--)
        cat();
#endif
#ifndef i_like_cats
    cat();
#endif
}
#pragma endregion main

Solution 2 (runtime: 46 ms):
/* ??????????????? ????????? ?????? ??? ??? ??????????|

?? ?????? ??????????????????? ????????????????????||  */



#include<bits/stdc++.h>

#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int f=1;

for(int j=i;j>0;j--){

if(s[j]-'0'-f>s[j-1]-'0'){

s[j]=(s[j]-f);

swap(s[j],s[j-1]);

}else break;

}

}

cout<<s<<"\n";



}

return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 234 ms):
// Cole Smith (colesmith54)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

    int n;
    cin >> n;

    vector<int> c(n);
    for (auto& x : c) cin >> x;

    vector<int> curr(n);
    iota(curr.begin(), curr.end(), 1);

    vector<int> idx(n + 1);
    iota(idx.begin(), idx.end(), -1);

    vector<pair<int, int>> ans;

    for (int i = n-1; i >= 0; i--) {
        int val = c[i];
        int curr_pos = idx[val];
        for (int j = curr_pos-1; j >= 0; j--) {
            int to_swap = curr[j];
            ans.emplace_back(val, to_swap);
            curr[j] = val; curr[j+1] = to_swap;
            idx[val]--; idx[to_swap]++;
        }

        while (idx[val] != i) {
            int j = idx[val] + 1;
            int to_swap = curr[j];
            ans.emplace_back(to_swap, val);
            curr[j-1] = to_swap; curr[j] = val;
            idx[to_swap]--; idx[val]++;
        }
    }

    cout << ans.size() << '\n';
    for (auto& [x, y] : ans) cout << x << ' ' << y << '\n';
}

Solution 2 (runtime: 218 ms):
#include<bits/stdc++.h>

#ifndef ONLINE_JUDGE
    #include "debug.cpp"
    extern void IO();
#else
    #define out(...) 
#endif

using namespace std;

void solve()
{
    int n;
    cin >> n;

    vector<int> v(n);
    for(int& i:v) cin >> i;
    vector<pair<int,int>> ans;

    for(int i=0; i<n; i++) {
        vector<int> g,s;
        for(int j=i+1; j<n; j++) {
            if(v[i]>v[j]) s.push_back(v[j]);
            else g.push_back(v[j]);
        }
        sort(g.begin(),g.end());
        sort(s.rbegin(),s.rend());
        int m = g.size();
        for(int j=0; j<m; j++) ans.push_back({g[j],v[i]});
        for(int j=m-1; j>-1; j--) ans.push_back({v[i],g[j]});
        m = s.size();
        for(int j=0; j<m; j++) ans.push_back({v[i],s[j]});
    }
    cout << ans.size() << '\n';
    for(auto& p:ans) {
        cout << p.first << ' ' << p.second << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    IO();
#endif
    int tc=1; //cin>>tc;
    while(tc--) solve();
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

void work()
{
	string a, b, c;
	cin >> a >> b >> c;
	int lena = a.size();
	int lenb = b.size();
	int lenc = c.size();
	a = "#" + a;
	b = "$" + b;
	c = "@" + c;
	vector<vector<int>> dp(lena + 5, vector<int>(lenb + 5));
	for (int i = 0; i <= lena; i++)
	{
		for (int j = 0; j <= lenb; j++)
		{
			int k = i + j;
			if (a[i] == c[k])
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1);
			}
			if (b[j] == c[k])
			{
				dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
			}
			if (i)
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			}
			if (j)
			{
				dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			}
		}
	}
	cout << lenc - dp[lena][lenb] << "\n";
}

int main()
{
	int T = 1;
	cin >> T;
	while (T--)
	{
		work();
	}
	return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n1=a.length(),n2=b.length(),n3=c.length();
        int dp[n3+1][n1+1];
        for(int i=0;i<=n3;i++){
            for(int j=0;j<=n1;j++){
                dp[i][j]=2e3+1;
            }
        }
        dp[0][0]=0;
        for(int i=1;i<=n3;i++) {
            for(int j=0; j<=min(i,n1);j++) {
                if(j>0&&c[i-1]==a[j-1]){
                    dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
                }
                else if(j>0){
                    dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1);
                }
                if(i-j>0&&c[i-1]==b[i-j-1]){
                    dp[i][j]=min(dp[i][j],dp[i-1][j]);
                }
                else if(i-j>0){
                    dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
                }
            }
        }
        cout<<dp[n3][n1]<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
    string a, b, c;
    cin>>a>>b>>c;
    vector<vector<ll>> dp(c.length()+1, vector<ll>(a.length()+1, 0));
    for(int i=1; i<=c.length(); i++) {
        for(int j=0; j<=a.length() && j<=i; j++) {
            int v1 = 1e9, v2 = 1e9;
            if(i-j > 0) v1 = dp[i-1][j] + ((c[i-1] == b[i-j-1]) ? 0 : 1);
            if(j > 0) v2 = dp[i-1][j-1] + ((c[i-1] == a[j-1]) ? 0 : 1);
            dp[i][j] = min(v1, v2);
        }
    }
    cout<<dp[c.length()][a.length()]<<'\n';
}

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

Solution 2 (runtime: 656 ms):
#include<bits/stdc++.h>

#define N 200005

#define inf 2147483647

#define ll long long

using namespace std;

char a[5005],b[5005],c[5005];

ll dp[5005][5005];

void solve()

{

    cin>>a>>b>>c;

    for(int i=0;i<=strlen(a);i++){

        for(int j=0;j<=strlen(b);j++){

            dp[i][j]=1e16;

        }

    }

    dp[0][0]=0;

    for(int i=1;i<=strlen(a);i++){

        if(a[i-1]!=c[i-1]) dp[i][0]=dp[i-1][0]+1;

        else dp[i][0]=dp[i-1][0];

    }

    for(int i=1;i<=strlen(b);i++){

        if(b[i-1]!=c[i-1]) dp[0][i]=dp[0][i-1]+1;

        else dp[0][i]=dp[0][i-1];

    }

    for(int i=1;i<=strlen(a);i++){

        for(int j=1;j<=strlen(b);j++){

            dp[i][j]=min(dp[i-1][j]+(a[i-1]!=c[i+j-1]),dp[i][j-1]+(b[j-1]!=c[i+j-1]));

        }

    }

    cout<<dp[strlen(a)][strlen(b)]<<"\n";

}

int main()

{

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

    int t;

    cin>>t;

    while(t--) solve();

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>

#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define rep(i, n) for (int i = 0; i < n; i++)

#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define BIGINT 1e9
#define nl "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define all(x) (x).begin(), (x).end()
#define li long long int

using namespace std;

li maxSum = 0;

void findMax(li a[], int n)
{
  if (n == 1)
  {
    li el = max(a[0], -1 * a[0]);
    maxSum = max(el, maxSum);
    return;
  }
  li sum = 0, newA[n - 1];
  for (int i = 0; i < n - 1; i++)
  {
    newA[i] = a[i + 1] - a[i];
    sum += newA[i];
  }
  sum = max(sum, -1 * sum);
  maxSum = max(maxSum, sum);

  findMax(newA, n - 1);
}

void solve()
{
  int n;
  li sum = 0;
  scanf("%d", &n);
  li a[n];
  rep(i, n)
  {
    scanf("%lld", a + i);
    sum += a[i];
  }

  if (n == 1)
  {
    printf("%lld\n", a[0]);
    return;
  }

  maxSum = max(sum, maxSum);
  findMax(a, n);
  printf("%lld\n", maxSum);
  maxSum = 0;
}

int main()
{
  int t;
  scanf("%d", &t);
  rep(i, t)
  {
    solve();
  }
}


Solution 2 (runtime: 46 ms):
// **************** MBRAHUL *************** 
#include<bits/stdc++.h>
#define ll long long
#define pn cout<<"NO"<<endl
#define py cout<<"YES"<<endl
#define vll vector<long long>
#define vi vector<int>
#define vb vector<bool>
#define u_map unordered_map
#define pll pair<long long,long long>
#define pii pair<int,int>
#define inf INT_MAX
#define pb push_back
#define mod 998244353
#define MOD 1000000007
#define ld long double
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define loop(i,n) for(int i=0;i<n;i++)
#define rloop(i, n) for(int i=n-1;i>=0;i--)
using namespace std;

void input(vector<ll>&arr,ll n){
for(ll i =0;i<n;i++)cin>>arr[i];
}

void printArr(vector<ll>&arr, ll i,ll j){
for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";
cout<<endl; 
}


void find(){
    int n;
    cin>>n;
    vll arr(n);
    loop(i,n)cin>>arr[i];
    int r = n;
    ll ans = -1e18;
    for(int op = 1;op<=n;op++){
        ll sum = 0;
        for(int i = 0;i<r;i++)sum+=arr[i];
        if(op==1)ans=sum;
        else ans = max(ans,abs(sum));
        for(int i = 0;i<r-1;i++)arr[i]=arr[i+1]-arr[i];
        r--;
    }
    cout<<ans<<endl;
}

int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll test=1;
cin>>test;
while(test--){
find();
}
return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
#define file if(fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FOD(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;

const int MAXN = 2e3 + 3;
const int MOD = 1e9 + 7;
const int INF = 1e9;

ll t, dp[MAXN][MAXN];
string a, b, c;

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

    file;

    cin >> t;
    while(t--) {
        cin >> a >> b >> c;
        a = ' ' + a;
        b = ' ' + b;
        c = ' ' + c;

        dp[0][0] = 0;
        for(int i = 1; i < a.size(); i++) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]);
        for(int i = 1; i < b.size(); i++) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]);

        for(int i = 1; i < a.size(); i++) {
            for(int j = 1; j < b.size(); j++) {
                dp[i][j] = min(dp[i - 1][j] + (a[i] != c[i + j]), dp[i][j - 1] + (b[j] != c[i + j]));
            }
        }

        cout << dp[a.size() - 1][b.size() - 1] << '\n';
    }

    cerr << "Time elapsed: " << TIME << " s.\n";

    return 0;
}

Solution 2 (runtime: 92 ms):
#include <bits/stdc++.h>
using namespace std;

int solve(int i, int j, string &a, string &b, string &c, vector<vector<int>>& dp) {
    if (i == a.length() && j == b.length()) {
        return 0;  
    }

    if (dp[i][j] != -1) return dp[i][j];  

    int k = i + j;  

    int result = INT_MAX;

    if (i < a.length() && a[i] == c[k]) {
        result = min(result, solve(i + 1, j, a, b, c, dp));
    }

    if (j < b.length() && b[j] == c[k]) {
        result = min(result, solve(i, j + 1, a, b, c, dp));
    }

    if (i < a.length() && a[i] != c[k]) {
        result = min(result, 1 + solve(i + 1, j, a, b, c, dp));
    }

    if (j < b.length() && b[j] != c[k]) {
        result = min(result, 1 + solve(i, j + 1, a, b, c, dp));
    }

    return dp[i][j] = result;
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        if (c.length() != a.length() + b.length()) {
            cout << -1 << endl;  
            continue;
        }

        vector<vector<int>> dp(a.length() + 1, vector<int>(b.length() + 1, -1));

        int result = solve(0, 0, a, b, c, dp);
        cout << result << endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define Int unsigned long long

void solve(){
	Int l,r;
	cin >> l >> r;

	vector<bool> bitsl, bitsr;

	
	for(Int temp=l;temp!=0; temp /=2)
		bitsl.push_back(temp%2);
	
	for(Int temp=r;temp!=0; temp /=2)
		bitsr.push_back(temp%2);

	// for(int i=0; i<bitsl.size(); i++)
	// 	cout << bitsl[i] << " ";
	// cout << endl;
	// for(int i=0; i<bitsr.size(); i++)
	// 	cout << bitsr[i] << " ";
	// cout << endl;

	int firstdiff;
	Int x=0;

	for(int i=max(bitsl.size(), bitsr.size())-1; i>=0; i--){
		if((i>=bitsl.size()) || (i>=bitsr.size())){
			firstdiff = i;
			x = (2*x+1)*(Int)pow(2,i);
			break;
		}
		else if((bitsl[i]!=bitsr[i])){
			firstdiff = i;
			x = (2*x+1)*(Int)pow(2,i);
			break;
		}
		else{
			x = 2*x+bitsl[i];
		}
	}
	
	Int y=x-1;
	Int z;
	if(l!=y) z=l;
	else if(l) z=l+2;

	cout << x << " "<<y << " "<<z<<endl;
}

int main(){
	int t;
	cin >> t;

	for(int i=0; i<t; i++){
		solve();
	}
}


Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
    int l,r;
    cin>>l>>r;
    int t=1<<(int)log2(l^r);
    int tt=~((t<<1)-1);
    t+=tt&l;
    if(t!=r)cout<<t<<" "<<t-1<<" "<<r<<endl;
    else cout<<t<<" "<<t-1<<" "<<l<<endl;    
}
signed main(){
    //freopen("./data.in","r",stdin);
    int test=1;
    cin>>test;
    while(test--){
        solve();
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long ll;
ll MOD = 998244353;
double eps = 1e-12;
#define fo(i,e) for(ll i = 0; i < e; i++)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 

int main()
{
 fast_cin();
 ll t;
 cin >> t;
while(t--){
    string s;
    cin>>s;
    ll sum=0, n2=0, n3=0;
    for(char c:s){
        int nc=c- '0';
        sum+=nc;
        n2+=(c == '2');
        n3+=(c == '3');
    }
    int mouhem = sum%9;
    bool pos=false;
    if(mouhem ==0){
        pos=true;

    }
    // dbg(mouhem);
    
    mouhem= 9 - mouhem;
     if(mouhem == 1){
        pos=false;
    }
    if (mouhem ==2){
        pos=(n2>=1);
    }else if (mouhem== 3 ){
        pos= (n2 >= 6 ) || (n3 >= 2);
    }else if (mouhem== 4 ){
        pos= (n2>= 2);
    }else if(mouhem== 5 ){
        pos=(n2 >= 7) || (n3 >= 2 && n2 >= 1);

    }else if (mouhem == 6){
        pos=(n3>=1) || (n2 >= 3 );

    }else if (mouhem == 7){
        pos=(n2>=8) || (n2 >=2 && n3 >= 2);
        
    }else if (mouhem == 8){
        pos=(n2 >= 4 ) || (n3 >= 1 && n2 >=1 );
        
    }
if(pos){
    cout<<"YES"<<ln;
    continue;
}
        for(int i=0; i<= n2; i++){
            for(int j=0; j<= n3; j++){
                if((2*i + 6*j- mouhem) %9 == 0){
                    pos=true;
                    break;
                }
            }

        }

    cout<<((pos)? "YES": "NO")<<endl;
    

}

 return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
const int N=200010;
typedef long long ll;
int n;
bool dp[N][10];
char s[N];
void sov(){
    int i,j,x;
    scanf("%s",s+1);
    n=strlen(s+1);
    dp[0][0]=1;
    for(i=1;i<=n;i++){
        x=s[i]-'0';
        for(j=0;j<9;j++) dp[i][(j+x)%9]=dp[i-1][j];
        x=x*x;
        if(x<=9) for(j=0;j<9;j++) dp[i][(j+x)%9]=dp[i][(j+x)%9]||dp[i-1][j];
    }
    if(dp[n][0]) printf("YES\n");
    else printf("NO\n");
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--) sov();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 140 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int,int> PII;
const int N=1e5+10;
int n,k;
void solve(){
	scanf("%d%d",&n,&k);
	map<int,int> mp;
	int mx=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	vector<int> v;
	for(auto &a:mp) v.push_back(a.second);
	sort(v.begin(),v.end());
	int m=v.size();
	for(int i=0;i<m-1;i++){
		if(k<v[i]){
			printf("%d\n",m-i);
			return;
		}
		k-=v[i];
	}
	puts("1");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
} 


Solution 2 (runtime: 93 ms):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) { cin >> a[i]; }
    sort(a.begin(), a.end());
    vector<int> b;
    int cnt = 1;
    for (int i = 1; i < n; i++) {
      if (a[i] == a[i - 1]) { cnt ++; }
      else {
        b.push_back(cnt);
        cnt = 1;
      }
    }
    b.push_back(cnt);
    sort(b.begin(), b.end());

    int ans = b.size();
    b.pop_back();
    for (auto e : b) {
      if (k >= e) {
        k -= e;
        ans --;
      } else break;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 827 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
void solve(){
	int n;
	cin>>n;
	set<pair<int,int> > s;
	map<int,int> mp;
	vector<pair<int,int> > vc;
	for(int i=1;i<=n-1;i++){
		int u,v;
		cin>>u>>v;
		s.insert({u,v});
		s.insert({v,u});
		mp[u]++;
		mp[v]++;
	}
	for(auto it:mp){
		vc.push_back({it.second,it.first});
	}
	sort(vc.begin(),vc.end());
	int ans=0;
	for(int i=n-1;vc[i].first>=vc[n-1].first&&i>=0;i--){
		for(int j=i-1;vc[j].first>=vc[i-1].first&&j>=0;j--){
			int temp=vc[i].first+vc[j].first;
			//cout<<temp<<endl;
			int u=vc[i].second;
			int v=vc[j].second;
			if(s.find({u,v})==s.end()){   //不相邻 
				temp--;
				ans=max(ans,temp);
				cout<<ans<<endl;
				return;
			}else{
				temp-=2;
			}
			ans=max(ans,temp);
		}
	}
	cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}

Solution 2 (runtime: 358 ms):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define lld long double
#define el '\n'
#define ws " "
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define nai cout << "-1\n"
#define pbk push_back
#define mkp make_pair
#define ii pair<int, int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define dbg(x) cout << #x << " " << x << "\n"
typedef vector<int> vi;
typedef vector<ll> vl;

template<class T>
void print(T& a)
{
    for(auto x : a)
        cout << x << " ";
    cout << "\n";
}

void solve(int tc)
{
    int n; cin >> n;

    vector<vi> adj(n + 1); 
    vi deg(n + 1);
    rep(i, n - 1) {
        int u, v; cin >> u >> v;
        deg[u]++;
        deg[v]++;
        adj[u].pbk(v);
        adj[v].pbk(u);
    }

    vi sdeg = deg;
    sort(all(sdeg));

    int mans = -1;
    for (int i = 1; i <= n; i++) {
        int ans = deg[i];
        vi ideg = {deg[i]};
        for (int vtx : adj[i]) 
            ideg.pbk(deg[vtx]);
        sort(rall(ideg));

        vi rem;
        for (int dg : ideg) {
            if (dg == sdeg.back()) {
                sdeg.pop_back();
                rem.pbk(dg);
            }
        }
        reverse(all(rem));

        int mx = -1;
        if (sdeg.size())
            mx = sdeg.back();
        for (int vtx : adj[i])
            mx = max(mx, deg[vtx] - 1);
        for (int dg : rem)
            sdeg.pbk(dg);

        mans = max(mans, ans + mx - 1);
    }
    cout << mans << el;
}

int32_t main(void)
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
        solve(i);
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 374 ms):
#include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>

using namespace std;

int main() {
  int num_tests;
  cin >> num_tests;

  for (int t = 0; t < num_tests; ++t) {
    int seq_length;
    cin >> seq_length;

    std::vector<int> seq(seq_length);
    for (int i = 0; i < seq_length; ++i) {
      cin >> seq[i];
    }

    bool non_decreasing = true;
    for (int i = 1; i < seq_length; ++i) {
      int m = min(seq[i - 1], seq[i]);
      seq[i - 1] -= m;
      seq[i] -= m;
      if (seq[i - 1] > seq[i]) {
        non_decreasing = false;
        std::cout << "NO" << std::endl;
        break;
      }
    }
    if (non_decreasing) {
      std::cout << "YES" << std::endl;
    }
  }
}


Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>

#define int long long

using namespace std;

vector<int>G[2010];

signed main() {

ios::sync_with_stdio(false); cin.tie(0);

int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int>a(n,0);

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

cin>>a[i];

}

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

int x=min(a[i],a[i+1]);

a[i]-=x;

a[i+1]-=x;

}

int flag=0;

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

if(a[i]>a[i+1]){

flag=1;

break;

}

}

if(flag==1)cout<<"NO"<<"\n";

else cout<<"YES"<<"\n";

}

return 0;

}