ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=2e5+5;

int a[N],n,x,y;

void work(){

    cin>>n>>x>>y;

    if(n&1){

        a[x]=2;

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

            x++;if(x==n+1)x=1;

            a[x]=(i&1);

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

        return;

    }

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

        a[i]=1,a[i+1]=0;

    if(a[x]==a[y]||x+1==y||(y+1==x)||(x==1&&y==n)||(x==n&&y==1)){

        if(a[x]==a[y])a[x]=2;

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }else{

        a[x]=2;int xx=x;

        int fl=0;

        while(1){

            x++;if(x==n+1)x=1;

            if(x==y)break;

            if(fl==0)a[x]=0;

            if(fl==1)a[x]=2;

            if(fl>=2)a[x]=(fl-1)&1;

            fl++;

        }

        fl=0;x=xx;

        while(1){

            x--;if(x==0)x=n;

            if(x==y)break;

            a[x]=(fl-1)&1;

            fl++;

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}

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

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=2e5+5;

int a[N],n,x,y;

void work(){

    cin>>n>>x>>y;

    if(n&1){

        a[x]=2;

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

            x++;if(x==n+1)x=1;

            a[x]=(i&1);

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

        return;

    }

    for(int i=1;i<=n;i+=2)a[i]=1,a[i+1]=0;

    if(x+1==y||(y+1==x)||(x==1&&y==n)||(x==n&&y==1)){

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

        return;

    }

    if(a[x]==a[y]){

        a[x]=2;

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

        return;

    }

    a[x]=2;int xx=x;

    int fl=0;

    while(1){

        x++;if(x==n+1)x=1;

        if(x==y)break;

        if(fl==0)a[x]=0;

        if(fl==1)a[x]=2;

        if(fl>=2)a[x]=(fl-1)&1;

        fl++;

    }

    fl=0;x=xx;

    while(1){

        x--;if(x==0)x=n;

        if(x==y)break;

        a[x]=(fl-1)&1;

        fl++;

    }

    for(int i=1;i<=n;i++)cout<<a[i]<<' ';

    cout<<endl;

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=2e5+5;

int a[N],n,x,y;

void work(){

    cin>>n>>x>>y;

    if(n&1){

        a[x]=2;

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

            x++;if(x==n+1)x=1;

            a[x]=(i&1);

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }

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

        a[i]=1,a[i+1]=0;

    if(a[x]==a[y]||x+1==y||(y+1==x)||(x==1&&y==n)||(x==n&&y==1)){

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }else{

        a[x]=2;int xx=x;

        int fl=0;

        while(1){

            x++;if(x==n+1)x=1;

            if(x==y)break;

            if(fl==0)a[x]=0;

            if(fl==1)a[x]=2;

            if(fl>=2)a[x]=(fl-1)&1;

            fl++;

        }

        fl=0;x=xx;

        while(1){

            x--;if(x==0)x=n;

            if(x==y)break;

            if(fl==0)a[x]=0;

            if(fl==1)a[x]=2;

            if(fl>=2)a[x]=(fl-1)&1;

            fl++;

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}

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

#define pii pair<int,int>

#define fi first

#define se second

#define ll long long

#define int long long

#define endl '\n'

#define ull unsigned long long

using namespace std;

const int N=2e5+5;

int a[N],n,x,y;

void work(){

    cin>>n>>x>>y;

    if(n&1){

        a[x]=2;

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

            x++;if(x==n+1)x=1;

            a[x]=(i&1);

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

        return;

    }

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

        a[i]=1,a[i+1]=0;

    if(a[x]==a[y]||x+1==y||(y+1==x)||(x==1&&y==n)||(x==n&&y==1)){

        if(a[x]==a[y])a[x]=2;

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }else{

        a[x]=2;int xx=x;

        int fl=0;

        while(1){

            x++;if(x==n+1)x=1;

            if(x==y)break;

            if(fl==0)a[x]=0;

            if(fl==1)a[x]=2;

            if(fl>=2)a[x]=(fl-1)&1;

            fl++;

        }

        fl=0;x=xx;

        while(1){

            x--;if(x==0)x=n;

            if(x==y)break;

            if(fl==0)a[x]=0;

            if(fl==1)a[x]=2;

            if(fl>=2)a[x]=(fl-1)&1;

            fl++;

        }

        for(int i=1;i<=n;i++)cout<<a[i]<<' ';

        cout<<endl;

    }

    return;

}

signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int T=1;

    cin>>T;

    while(T--)work();

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ; 
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( a[i] > a[j] )
            {
                vc2.push_back( { a[j] , a[i] } ) ;
            }
            else// this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i =  vc1.size() - 1 ; i >= 0 ; i-- )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    cout << ans.size() << endl ;
    for( auto it : ans )
    {
        cout << it.first << " " << it.second << endl ;
    }
    return 0 ;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( i < n && j < n && a[i] > a[j] )
            {
                vc2.push_back( { a[j] , a[i] } ) ;
            }
            else if( i < n && j < n ) // this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i = vc1.size(); i-- > 0; )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( a[i] > a[j] )
            {
                vc2.push_back( { a[i] , a[j] } ) ;
            }
            else// this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i =  vc1.size() - 1 ; i >= 0 ; i-- )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ; 
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( a[i] > a[j] )
            {
                vc2.push_back( { a[j] , a[i] } ) ;
            }
            else// this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i =  vc1.size() - 1 ; i >= 0 ; i-- )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    cout << ans.size() << endl ;
    for( auto it : ans )
    {
        cout << it.first << " " << it.second << endl ;
    }
    return 0 ;
}

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( i < n && j < n && a[i] > a[j] )
            {
                vc2.push_back( { a[j] , a[i] } ) ;
            }
            else if( i < n && j < n ) // this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i = vc1.size(); i-- > 0; )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( a[i] > a[j] )
            {
                vc2.push_back( { a[i] , a[j] } ) ;
            }
            else// this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i =  vc1.size() - 1 ; i >= 0 ; i-- )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}

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

using namespace std ;

typedef long long int ll ; 

int main()
{
    ll n ;
    cin >> n ;
    vector<ll> a(n) ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[i] ;
    }
    
    //LOGIC
    
    vector<pair<ll,ll>> ans ;
    for( ll i = 0 ; i < n ; i++ )
    {
        ll b = a[i] ;
        vector<pair<ll,ll>> vc1, vc2, vc3 ; 
        for( ll j = i + 1 ; j < n ; j++ )
        {
            if( i < n && j < n && a[i] > a[j] )
            {
                vc2.push_back( { a[i] , a[j] } ) ;
            }
            else if( i < n && j < n ) // this says that all the members are greater than a[i] 
            {
                vc1.push_back( { a[j] , a[i] } ) ;
            }
        }
        sort( vc1.begin() , vc1.end() ) ;
        sort( vc2.begin() , vc2.end() ) ;
        reverse( vc2.begin() , vc2.end() ) ;
        for( ll i = vc1.size(); i-- > 0; )
        {
            vc3.push_back( { vc1[i].second , vc1[i].first } ) ;
        }
        for( ll i = 0 ; i < vc1.size() ; i++ )
        {
            ans.push_back(vc1[i]) ;
        }
        for( ll i = 0 ; i < vc3.size() ; i++ )
        {
            ans.push_back( vc3[i] ) ;
        }
        for( ll i = 0 ; i < vc2.size() ; i++)
        {
            ans.push_back( vc2[i] ) ;
        }
    }
    
    cout << ans.size() << endl ;
    for( ll i = 0; i < ans.size() ; i++ )
    {
        cout << ans[i].first << " " << ans[i].second << endl ;
    }
    return 0 ;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

string func(int n, vector<int> &vec) {
    for (int i = 0; i < n - 1; i++) {
        if (vec[i] > vec[i + 1]) {
            return "NO";
        }
    }
    return "YES";
}


int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}

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

bool canBeNonDecreasing(vector<long long>& sequence) {
    for (int i = 0; i < (int)sequence.size() - 1; i++) {
        if (sequence[i] > sequence[i + 1]) {
            // Check if the difference can be resolved by the given operation
            if (sequence[i] - sequence[i + 1] > sequence[i + 1]) {
                return false;
            }
        }
    }
    return true;
}

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

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> sequence(n);
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }

        cout << (canBeNonDecreasing(sequence) ? "YES\n" : "NO\n");
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

string func(int n, vector<int> &vec) {
    int i=0;
    int j=1;
    int found=0;
    while(j<n){
      if(vec[i]>vec[j]){found=1;break;}
      i+=2;j+=2;
    }
    if(found)return "NO";
    return "Yes";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

bool canBeNonDecreasing(vector<long long>& sequence) {
    for (int i = 0; i < (int)sequence.size() - 1; i++) {
        if (sequence[i] > sequence[i + 1]) {
            // Check if the difference can be resolved by the given operation
            if (sequence[i] - sequence[i + 1] > sequence[i + 1]) {
                return false;
            }
        }
    }
    return true;
}

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

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> sequence(n);
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }

        cout << (canBeNonDecreasing(sequence) ? "YES\n" : "NO\n");
    }
    return 0;
}


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

string func(int n, vector<int> &vec) {
   
    for(int i=0;i<n-1;i++){
            if(vec[i]>vec[i+1])return "NO";
            else{
                int mini=min(vec[i],vec[i+1]);
                vec[i]=0;
                vec[i+1]-=mini;
            }
    }
    return "YES";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

string func(int n, vector<int> &vec) {
    int i=0;
    int j=1;
    int found=0;
    while(j<n){
      if(vec[i]>vec[j]){found=1;break;}
      i+=2;j+=2;
    }
    if(found)return "NO";
    return "Yes";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}

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

string func(int n, vector<int> &vec) {
    for (int i = 0; i < n - 1; i++) {
        if (vec[i] > vec[i + 1]) {
            return "NO";
        }
    }
    return "YES";
}


int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for (int i = 0; i < n; i++) {
            cin >> vec[i];
        }
        string result = func(n, vec);
        cout << result<<endl;
       
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
import heapq




tc = int(input())
for _ in range(0,tc):
  n = int(input())
  
  graph = [[] for i in range(0,n)]
  for i in range(0,n-1):
    inp_arr = [int(i) for i in input().split()]
    v1 = inp_arr[0]-1
    v2 = inp_arr[1]-1
    graph[v1].append(v2)
    graph[v2].append(v1)
  
  edge_count = []
  for i in range(0,n):
    heapq.heappush(edge_count,(-len(graph[i]),i))
  if(n==2):
    print(0)
  else:  
    v1 = heapq.heappop(edge_count)
    v2 = heapq.heappop(edge_count)
    v3 = heapq.heappop(edge_count)
    
    if(v1[0] == v2[0]==v3[0]):
      print(2*-v1[0]-1)
    else:
      
      v1_connections = set()
      for i in range(0,len(graph[v1[1]])):
        v1_connections.add(graph[v1[1]][i])
      
      if(v2[0]!=v3[0]):
        add = -1 if v2[1] in v1_connections else 0
        print(graph)
        print(v1_connections)
        print(-v1[0]-v2[0]-1+add)
      else: 
        same_cons = [v2[1],v3[1]]
        l = v2[0]
        while(len(edge_count) > 0):
          v = heapq.heappop(edge_count)
          if(v[1] == l):
            same_cons.append(v[1])
          else:
            break
        
        add = -1  
        for v in same_cons:
          if(v not in v1_connections):
            add = 0
            break
        print(-v1[0]-v2[0]-1+add)