ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


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

using ll = long long;
using ld = long double;
using namespace std;
#define endl "\n";
#define ff first
#define ss second

void solve(){
    string s;
    cin>>s;
    int x2=0;
    int x3=0;
    int s1=0;
    for(int i=0;i<s.size();i++){
        s1+=int(s[i]-48);
        if(int(s[i]-48)==2){
            x2++;
        }
        if(int(s[i]-48)==3){
            x3++;
        }
    }
    s1=s1%9;
    s1=(9-s1);
    bool ans=false;
        if(s1==1){
            if(x2>=5){
                ans=true;
            }
        }
        if(s1==3){
            if(x2>=15||(x3>=2)){
                ans=true;
            }
        }
        if(s1==5){
            if(x2>=25||(x3>=2&&x2>=10)){
                ans=true;
            }
        }
        if(s1==7){
            if(x2>=35||(x3>=2&&x2>=20)||(x2>=1&&x2>=5)){
                ans=true;
            }
        }
        if(s1==9){
            ans=true;
        }
            if(s1==2){
                if(x2>=1){
                    ans=true;
                }
            }
            if(s1==4){
                if(x2>=2){
                    ans=true;
                }
            }
            if(s1==6){
                if(x3>=1||x2>=3){
                    ans=true;
                }
            }
            if(s1==8){
                if(x2>=4||(x3>=1&&x2>=1)){
                    ans=true;
                }
            }
        
    if(ans){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }


}

int main() {
    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

using ll = long long;
using ld = long double;
using namespace std;
#define endl "\n";
#define ff first
#define ss second

void solve(){
    string s;
    cin>>s;
    int x2=0;
    int x3=0;
    int s1=0;
    for(int i=0;i<s.size();i++){
        s1+=int(s[i]-48);
        if(int(s[i]-48)==2){
            x2++;
        }
        if(int(s[i]-48)==3){
            x3++;
        }
    }
    s1=s1%9;
    s1=(9-s1);
    bool ans=false;
        if(s1==1){
            if(x2>=5||(x3>=1&&x2>=2)){
                ans=true;
            }
        }
        if(s1==3){
            if(x2>=15||(x3>=2)){
                ans=true;
            }
        }
        if(s1==5){
            if(x2>=25||(x3>=2&&x2>=1)){
                ans=true;
            }
        }
        if(s1==7){
            if(x2>=35||(x3>=2&&x2>=2)||(x2>=1&&x2>=5)){
                ans=true;
            }
        }
        if(s1==9){
            ans=true;
        }
            if(s1==2){
                if(x2>=1){
                    ans=true;
                }
            }
            if(s1==4){
                if(x2>=2){
                    ans=true;
                }
            }
            if(s1==6){
                if(x3>=1||x2>=3){
                    ans=true;
                }
            }
            if(s1==8){
                if(x2>=4||(x3>=1&&x2>=1)){
                    ans=true;
                }
            }
        
    if(ans){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }


}

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


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

using ll = long long;
using ld = long double;
using namespace std;
#define endl "\n";
#define ff first
#define ss second

void solve(){
    string s;
    cin>>s;
    int x2=0;
    int x3=0;
    int s1=0;
    for(int i=0;i<s.size();i++){
        s1+=int(s[i]-48);
        if(int(s[i]-48)==2){
            x2++;
        }
        if(int(s[i]-48)==3){
            x3++;
        }
    }
    bool ans=false;
   for(int i=0;i<min(10,x2+1);i++){
    for(int j=0;j<min(4,x3+1);j++){
        if ((s1 + i * 2 + j * 6) % 9 == 0){
            ans=true;
            break;
        }
    }
   }
        
    if(ans){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }


}

int main() {
    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>>res;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
            }
        }
        v[a[i]]=1;
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i-1;j>=0;j--){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[i],a[j]});
            t=j;
        }
        for(int j=t;j<i;j++) res.push_back({a[j],a[i]});
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}

Submission (verdict: Wrong answer on test 12):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>> res,res1;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
                f.insert({j,a[i]});
            }
        }
        v[a[i]]=1;
    }
    for(int i=1;i<=n;i++){
        int t=i;
        for(int j=i+1;j<=n;j++){
            if(f.find({j,i})!=f.end()) break;
            res1.push_back({j,i});
            f.insert({j,i});
            f.insert({i,j});
            t=j;
        }
        for(int j=t;j>i;j--) res1.push_back({i,j});
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i-1;j>=0;j--){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[i],a[j]});
            t=j;
        }
        for(int j=t;j<i;j++) res.push_back({a[j],a[i]});
    }
    cout<<res1.size()+res.size()<<'\n';
    for(auto [x,y]:res1) cout<<x<<" "<<y<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>>res;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
            }
        }
        v[a[i]]=1;
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i-1;j>=0;j--){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[i],a[j]});
            t=j;
        }
        for(int j=t;j<i;j++) res.push_back({a[j],a[i]});
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 12):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>> res,res1;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
                f.insert({j,a[i]});
            }
        }
        v[a[i]]=1;
    }
    for(int i=1;i<=n;i++){
        int t=i;
        for(int j=i+1;j<=n;j++){
            if(f.find({j,i})!=f.end()) break;
            res1.push_back({j,i});
            f.insert({j,i});
            f.insert({i,j});
            t=j;
        }
        for(int j=t;j>i;j--) res1.push_back({i,j});
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i-1;j>=0;j--){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[i],a[j]});
            t=j;
        }
        for(int j=t;j<i;j++) res.push_back({a[j],a[i]});
    }
    cout<<res1.size()+res.size()<<'\n';
    for(auto [x,y]:res1) cout<<x<<" "<<y<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}

Submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>> res;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
                f.insert({j,a[i]});
            }
        }
        v[a[i]]=1;
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i+1;j<n;j++){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[j],a[i]});
            t=j;
        }
        for(int j=t;j>i;j--) res.push_back({a[i],a[j]});
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),v(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<pair<int,int>> res;
    set<pair<int,int>> f;
    for(int i=0;i<n;i++){
        for(int j=a[i]-1;j;j--){
            if(v[j]==0){
                res.push_back({a[i],j});
                f.insert({a[i],j});
                f.insert({j,a[i]});
            }
        }
        v[a[i]]=1;
    }
    for(int i=0;i<n;i++){   
        int t=i;
        for(int j=i+1;j<n;j++){
            if(f.find({a[j],a[i]})!=f.end()) break;
            res.push_back({a[j],a[i]});
            t=j;
        }
        for(int j=t;j>i;j--) res.push_back({a[i],a[j]});
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    int n;
    cin>>n;
    vector<int> a(n),x(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) x[a[i]]=i;
    vector<pair<int,int>> res;
    vector<int> now;
    for(int i=1;i<=n;i++){
        int k=now.size();
        now.push_back(i);
        for(int j=k-1;j>=0;j--){
            res.push_back({i,now[j]});
            swap(now[j],now[j+1]);
        }
        for(int j=0;j<k;j++){
            if(x[i]>x[now[j+1]]){
                res.push_back({now[j+1],i});
                swap(now[j+1],now[j]);
            }
            else break;
        }
    }
    cout<<res.size()<<'\n';
    for(auto [x,y]:res) cout<<x<<" "<<y<<'\n';
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T=1;
    // cin>>T;
    while(T--) solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }
        
        // output the minimum number of operations to make the array a empty
        // everytime i can pick the element with highest frequency and remove it from the array
        // first it is always beneficial to use
        // 9 8 9 9 8
        // 9 8 9 7 9 8, k = 2
        // 9 8 8 8 9
        // answer is the number of distinct elements in the hash map we'd want to decrease it
        // 1 2 3 2, k = 2
        
        // 1 -> 0
        // 2 -> 0
        // 3 -> 8
        // 4 -> 3        
        vector<int> freq;
        for(auto it : m) {
            freq.push_back(it.second);
        }
        
        sort(freq.begin(), freq.end());
        
        
        for(int i = 0; i<freq.size() && k>0; i++) {
            if(freq[i] <= k) {
                k -= freq[i];
                freq[i] = 0;
            }
        }
        
        int cnt = 0;
        for(auto it : freq) {
            if(it!=0) {
                cnt++;
            }
        }
        if(cnt == 0) cnt+=1;
        cout<<cnt<<endl;
    }
    
    return 0;
}

Submission (verdict: Time limit exceeded on test 2):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }
        priority_queue<int, vector<int>, greater<int>> pq;

        for(auto it :  m) {
            pq.push(it.second);
        }

        while(!pq.empty() && k>0) {
            int top = pq.top();
            if(top<=k) {
                pq.pop();
                k -= top;
            } 
        }

        cout<<(pq.size()==0 ? 1: pq.size())<<endl;
    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }
        
        // output the minimum number of operations to make the array a empty
        // everytime i can pick the element with highest frequency and remove it from the array
        // first it is always beneficial to use
        // 9 8 9 9 8
        // 9 8 9 7 9 8, k = 2
        // 9 8 8 8 9
        // answer is the number of distinct elements in the hash map we'd want to decrease it
        // 1 2 3 2, k = 2
        
        // 1 -> 0
        // 2 -> 0
        // 3 -> 8
        // 4 -> 3        
        vector<int> freq;
        for(auto it : m) {
            freq.push_back(it.second);
        }
        
        sort(freq.begin(), freq.end());
        
        
        for(int i = 0; i<freq.size() && k>0; i++) {
            if(freq[i] <= k) {
                k -= freq[i];
                freq[i] = 0;
            }
        }
        
        int cnt = 0;
        for(auto it : freq) {
            if(it!=0) {
                cnt++;
            }
        }
        if(cnt == 0) cnt+=1;
        cout<<cnt<<endl;
    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }

        vector<int> cnt;
        for(auto it : m) {
            cnt.push_back(it.second);
        }

        sort(cnt.begin(), cnt.end());
       
        int ms = cnt.size();

        bool flag = false;
        for(int i = 0; i<ms-1; i++) {
            if(cnt[i]>k) {
                cout<<(ms-i)<<"\n";
                flag = true;
                break;
            }
            k-=cnt[i];
        }
        if(!flag) cout<<1<<"\n";
    }
    
    return 0;
}

Submission (verdict: Accepted):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        vector<int> a(n);
        vector<int> cnt = {1};
        for(int i  = 0; i<n; i++) {
            cin>>a[i];
        }
        sort(a.begin(), a.end());
        
        for(int i = 1; i<n; i++) {
            if(a[i] == a[i-1]) {
                cnt.back()++;
            } else {
                cnt.emplace_back(1);
            }
        }

        sort(cnt.begin(), cnt.end());
       
        int ms = cnt.size();

        bool flag = false;
        for(int i = 0; i<ms-1; i++) {
            if(cnt[i]>k) {
                cout<<(ms-i)<<"\n";
                flag = true;
                break;
            }
            k-=cnt[i];
        }
        if(!flag) cout<<1<<"\n";
    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 2):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }
        priority_queue<int, vector<int>, greater<int>> pq;

        for(auto it :  m) {
            pq.push(it.second);
        }

        while(!pq.empty() && k>0) {
            int top = pq.top();
            if(top<=k) {
                pq.pop();
                k -= top;
            } 
        }

        cout<<(pq.size()==0 ? 1: pq.size())<<endl;
    }
    
    return 0;
}

Submission (verdict: Time limit exceeded on test 11):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--) {
        int n,k;
        cin>>n>>k;
        
        unordered_map<int, int> m;
        for(int i = 0; i<n; i++) {
            int u;
            cin>>u;
            m[u]++;
        }

        vector<int> cnt;
        for(auto it : m) {
            cnt.push_back(it.second);
        }

        sort(cnt.begin(), cnt.end());
       
        int ms = cnt.size();

        bool flag = false;
        for(int i = 0; i<ms-1; i++) {
            if(cnt[i]>k) {
                cout<<(ms-i)<<"\n";
                flag = true;
                break;
            }
            k-=cnt[i];
        }
        if(!flag) cout<<1<<"\n";
    }
    
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#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;
#define int long long
#define mod 1000000007
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
double eps = 1e-12;
#define ln "\n"
#define printVector(a) for(int i=0; i<a.size(); i++){cout<<a[i]<<" ";}cout<<ln;
#define print_array(a,n) for(int i=0; i<n; i++){cout<<a[i]<<" ";}cout<<ln;
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define take_vector(a) for(auto &x:a)cin>>x;
#define take_array(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define take_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cin>>a[i][j];}}
#define print_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cout<<a[i][j]<<" ";}cout<<ln;}
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/gcd(a,b))*b
#define count(a,x) count(a.begin(), a.end(),x)  
#define sum(a) accumulate(a.begin(), a.end(),0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())

int32_t main()
{
  fast_cin();

  int t;
  cin >> t;

  while (t--)
  {

    int n,m;
    cin>>n>>m;

    map<int,int> mp1;
    map<int,int,greater<int>> mp2;

    vector<int> a(n,0);
    for( int i = 0; i < n;  i++ ){ cin>>a[i]; mp1[a[i]]++; }

    vector<int> b(m,0);
    for( int i = 0; i < m ; i++ ){ cin>>b[i]; mp2[b[i]]++; }

    if( sum(a) != sum(b) ){ cout<<"NO"<<endl; continue; }

    while( mp1.size() and mp2.size() ){

        auto it = mp2.begin();

        int num = it->first;

        // dbg(num);

        int f1 = it->second;
       
        if( mp1.find(num) != mp1.end() ){
            int f2 = mp1[num];

            int toDel = min(f1,f2);

            mp2[num] -= toDel;
            mp1[num] -= toDel;

            if( mp2[num] == 0 ) mp2.erase(num);
            if( mp1[num] == 0 ) mp1.erase(num);    

        }
        else{

            if( num == 1 ) break;

            int x = num/2;
            int y = (num+1)/2;
            mp2[x]++; mp2[y]++;

            mp2[num]--;

            if( mp2[num] == 0 ) mp2.erase(num);

            
        }

    }

    if( mp1.empty() and mp2.empty() ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

  }
  return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        if(a[2]>a[1]){
            cout<<"YES"<<endl;
        }
        else if(a[1]==a[2]){
            ll fl=0;
            for(int i=3; i<=n; i+=2){
                if(a[i]>a[i+1] && i!=n)fl=1;
            }
            if(fl){
                cout<<"NO"<<endl;

            }
            else cout<<"YES"<<endl;

        }
        else{
            cout<<"NO"<<endl;
        }
    }


    return 0;
}