ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

bool b(vector<long long> v) {
    int a = 0, b = 0;
    for (int i = 0; i < v.size() / 2; ++i) {
        a += v[i];
    }
    for (int i = v.size() / 2; i < v.size(); ++i) {
        b += v[i];
    }
    if (b < a)return true;
    return false;
}

vector<long long> o(vector<long long> v) {
    if (v.size() == 1)return v;
    vector<long long> v1(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    return v1;
}

long long sum(vector<long long> v) {
    long long s = 0;
    for (auto it: v)s += it;
    return s;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<long long> v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = sum(v);

    do {
        if (b(v))reverse(all(v));
        v1 = o(v);
        v = v1;
        s = max(s, sum(v));
    } while (v1.size() > 1);

    cout << s << "\n";
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef vector<int> vi;

void solve();

long long sum(vector<long long> v) {
    long long s = 0;
    for (auto it: v)s += it;
    return s;
}

vector<long long> b(vector<long long> v) {
    vector<long long> v1(v.size() - 1), v2(v.size() - 1);
    for (int i = 1; i < v.size(); ++i) {
        v1[i - 1] = v[i] - v[i - 1];
    }
    reverse(all(v));
    for (int i = 1; i < v.size(); ++i) {
        v2[i - 1] = v[i] - v[i - 1];
    }
    return sum(v1) > sum(v2) ? v1 : v2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<long long> v(n), v1;
    for (auto &it: v)cin >> it;
    long long s = sum(v);
    if (v.size() == 1) {
        cout << v.back() << "\n";
        return;
    }
    do {
        v1 = b(v);
        v = v1;
        s = max(s, sum(v));
    } while (v1.size() > 1);

    cout << s << "\n";
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=rem+s[i]-48;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        if(rem==0){

        cout<<"YES"<<endl;

        continue;

        }

        rem=9-rem;

        if(rem%2){

            rem+=9;

        }

        while(three&&rem-6>=0){

            rem-=6;

            three--;

        }

        if(rem==0)

        cout<<"YES"<<endl;

        else{

            while(two>0&&rem-2>=0){

                rem-=2;

                two--;

            }

            if(rem==0)

            cout<<"YES"<<endl;

            else

            cout<<"NO"<<endl;

        }



    }

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=rem+s[i]-48;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        rem=rem%9;

        if(rem==0){

        cout<<"YES"<<endl;

        continue;

        }

        rem=9-rem;

        if(rem%2){

            rem+=9;

        }

        while(three&&rem-6>=0){

            rem-=6;

            three--;

        }

        if(rem==0)

        cout<<"YES"<<endl;

        else{

            while(two>0&&rem-2>=0){

                rem-=2;

                two--;

            }

            if(rem==0)

            cout<<"YES"<<endl;

            else

            cout<<"NO"<<endl;

        }



    }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=(rem+s[i]-48)%9;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        rem=9-rem;

        if(rem%2){

            rem+=9;

        }

        while(three&&rem-6>=0){

            rem-=6;

            three--;

        }

        if(rem==0)

        cout<<"YES"<<endl;

        else{

            while(two>0&&rem-2>=0){

                rem-=2;

                two--;

            }

            if(rem==0)

            cout<<"YES"<<endl;

            else

            cout<<"NO"<<endl;

        }



    }

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=rem+s[i]-48;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        if(rem==0){

        cout<<"YES"<<endl;

        continue;

        }

        rem=9-rem;

        if(rem%2){

            rem+=9;

        }

        while(three&&rem-6>=0){

            rem-=6;

            three--;

        }

        if(rem==0)

        cout<<"YES"<<endl;

        else{

            while(two>0&&rem-2>=0){

                rem-=2;

                two--;

            }

            if(rem==0)

            cout<<"YES"<<endl;

            else

            cout<<"NO"<<endl;

        }



    }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=(rem+s[i]-48)%9;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        two+=3*three;

        if(rem%2){

            rem+=9;

        }

        if(2*two>=rem){

            cout<<"YES"<<endl;

        }

        else

        cout<<"NO"<<endl;



    }

}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=(rem+s[i]-48)%9;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        rem=9-rem;

        if(rem%2){

            rem+=9;

        }

        while(three&&rem-6>=0){

            rem-=6;

            three--;

        }

        if(rem==0)

        cout<<"YES"<<endl;

        else{

            while(two>0&&rem-2>=0){

                rem-=2;

                two--;

            }

            if(rem==0)

            cout<<"YES"<<endl;

            else

            cout<<"NO"<<endl;

        }



    }

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int rem=0;

        long long two=0,three=0;

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

            rem=(rem+s[i]-48)%9;

            if(s[i]=='2')

            two++;

            else if(s[i]=='3')

            three++;

        }

        two+=3*three;

        if(rem%2){

            rem+=9;

        }

        if(2*two>=rem){

            cout<<"YES"<<endl;

        }

        else

        cout<<"NO"<<endl;



    }

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n=s.length();

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

int index=-1;

int maxdiff=0;

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

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

cout<<s<<endl;

}

}

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n=s.length();

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

int index=-1;

int maxdiff=0;

for(int j=i+1;j<min(10+i+1,n);j++){

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

cout<<s<<endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string st;

cin>>st;

int n=st.length();

vector<char> s;

for(auto i: st){

s.push_back(i);

}

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

int index=-1;

int maxdiff=0;

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

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

for(auto i:s)

cout<<i;

cout<<endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string st;

cin>>st;

int n=st.length();

vector<char> s;

for(auto i: st){

s.push_back(i);

}

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

int index=-1;

int maxdiff=0;

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

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

for(auto i:s)

cout<<i;

cout<<endl;

}

}

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n=s.length();

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

int index=-1;

int maxdiff=0;

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

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

cout<<s<<endl;

}

}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#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);
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> counts;
        unordered_map<int,int> cnt;
        for(int i=0;i<n;i++){
            cnt[a[i]]++;
        }
        for(auto i:cnt){
            counts.push_back(i.second);
        }
        sort(counts.begin(),counts.end());
        int sum=0;
        int op=0;
        for(int i=0;i<counts.size();i++){
            if(sum+counts[i]<=k){
                sum+=counts[i];
            }
            else{
                op=counts.size()-i;
                break;
            }
        }
        if(op){
            cout<<op<<endl;
        }
        else
        cout<<1<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#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);
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> counts;
        int cnt=1;
        sort(a.begin(),a.end());
        for(int i=1;i<n;i++){
            if(a[i]==a[i-1]){
                cnt++;
                if(i==n-1){
                    counts.push_back(cnt);
                }
            }
            else{
                counts.push_back(cnt);
                cnt=1;
            }
        }
        sort(counts.begin(),counts.end());
        int sum=0;
        int op=0;
        for(int i=0;i<counts.size();i++){
            if(sum+counts[i]<=k){
                sum+=counts[i];
            }
            else{
                op=counts.size()-i;
                break;
            }
        }
        if(op){
            cout<<op<<endl;
        }
        else
        cout<<1<<endl;
    }
}

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);
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> counts;
        int cnt=1;
        sort(a.begin(),a.end());
        for(int i=1;i<n;i++){
            if(a[i]==a[i-1]){
                cnt++;
            }
            else{
                counts.push_back(cnt);
                cnt=1;
            }
        }
        counts.push_back(cnt);
        sort(counts.begin(),counts.end());
        int sum=0;
        int op=0;
        for(int i=0;i<counts.size();i++){
            if(sum+counts[i]<=k){
                sum+=counts[i];
            }
            else{
                op=counts.size()-i;
                break;
            }
        }
        if(op){
            cout<<op<<endl;
        }
        else
        cout<<1<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#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);
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> counts;
        unordered_map<int,int> cnt;
        for(int i=0;i<n;i++){
            cnt[a[i]]++;
        }
        for(auto i:cnt){
            counts.push_back(i.second);
        }
        sort(counts.begin(),counts.end());
        int sum=0;
        int op=0;
        for(int i=0;i<counts.size();i++){
            if(sum+counts[i]<=k){
                sum+=counts[i];
            }
            else{
                op=counts.size()-i;
                break;
            }
        }
        if(op){
            cout<<op<<endl;
        }
        else
        cout<<1<<endl;
    }
}

Submission (verdict: Wrong answer on test 1):
#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);
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> counts;
        int cnt=1;
        sort(a.begin(),a.end());
        for(int i=1;i<n;i++){
            if(a[i]==a[i-1]){
                cnt++;
                if(i==n-1){
                    counts.push_back(cnt);
                }
            }
            else{
                counts.push_back(cnt);
                cnt=1;
            }
        }
        sort(counts.begin(),counts.end());
        int sum=0;
        int op=0;
        for(int i=0;i<counts.size();i++){
            if(sum+counts[i]<=k){
                sum+=counts[i];
            }
            else{
                op=counts.size()-i;
                break;
            }
        }
        if(op){
            cout<<op<<endl;
        }
        else
        cout<<1<<endl;
    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

long long mod=998244353;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> a(n);

        long long ans=0;

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

        cin>>a[i];

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

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

        ans+=a[i];

        cout<<ans<<endl;

    }

}

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

using namespace std;

long long mod=998244353;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        int a[n];

        vector<int> b;

        long long ans1=0;

        long long ans2=0;

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

        cin>>a[i];

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

        b.push_back(a[i]);

        sort(a,a+r-1);

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

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

        ans1+=a[i];

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

        ans2+=b[i];

        cout<<min(ans1,ans2)<<endl;

    }

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


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

using namespace std;

long long mod=998244353;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> a(n);

        long long ans=0;

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

        cin>>a[i];

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

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

        ans+=a[i];

        cout<<ans<<endl;

    }

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

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

using namespace std;

long long mod=998244353;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        int a[n];

        vector<int> b;

        long long ans1=0;

        long long ans2=0;

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

        cin>>a[i];

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

        b.push_back(a[i]);

        sort(a,a+r-1);

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

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

        ans1+=a[i];

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

        ans2+=b[i];

        cout<<min(ans1,ans2)<<endl;

    }

}

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

using namespace std;

long long mod=998244353;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        int a[n];

        vector<int> b;

        long long ans1=0;

        long long ans2=0;

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

        cin>>a[i];

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

        b.push_back(a[i]);

        sort(a,a+r);

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

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

        ans1+=a[i];

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

        ans2+=b[i];

        cout<<min(ans1,ans2)<<endl;

    }

}
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;
#define vii vector<int> 
#define vll vector<long long>
#define pb push_back
#define ll long long
#define iterate(i,a,b) for(ll i=a;i<b;i++)
void solve(){
ll n; cin>>n;
vll arr(n); iterate(i,0,n) cin>>arr[i];
bool sorted=true;
iterate(i,1,n){
if(arr[i]<arr[i-1]) sorted=false;
}
if(sorted){
cout<<"YES"<<endl;
return;
}
ll maxi=*max_element(arr.begin(),arr.end());
iterate(i,1,n){
    if(arr[i]>arr[i-1] && arr[i]==maxi){
        cout<<"YES"<<endl;
        return;
    }
}
cout<<"NO"<<endl;
}
int main()
{
ll t;
cin>>t; 
while(t--){
solve();
}
    return 0;
}

Submission (verdict: Wrong answer on test 2):
/*
#       #      #   #######     #     #
#       #      #   #            #   #
#       #      #   #             # #
#       #      #   #              # 
#       #      #   #              # 
######  ########   #######        # 
*/
#include<bits/stdc++.h>
using namespace std;
#define vii vector<int> 
#define vll vector<long long>
#define pb push_back
#define ll long long
#define iterate(i,a,b) for(ll i=a;i<b;i++)
void solve(){
ll n; cin>>n;
vll arr(n); iterate(i,0,n) cin>>arr[i];
bool sorted=true;
iterate(i,1,n){
if(arr[i]<arr[i-1]) sorted=false;
}
if(sorted){
cout<<"YES"<<endl;
return;
}
ll maxi=*max_element(arr.begin(),arr.end());
if(n==3 && arr[1]!=maxi){
  cout<<"NO"<<endl;
  return;
}
else if(n==3 && arr[1]==maxi){
    cout<<"YES"<<endl;
    return;
  }
iterate(i,1,n){
    if(arr[i]>arr[i-1] && arr[i]==maxi){
        cout<<"YES"<<endl;
        return;
    }
}
cout<<"NO"<<endl;
}
int main()
{
ll t;
cin>>t; 
while(t--){
solve();
}
    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;
#define vii vector<int> 
#define vll vector<long long>
#define pb push_back
#define ll long long
#define iterate(i,a,b) for(ll i=a;i<b;i++)
void solve(){
ll n; cin>>n;
vll arr(n); iterate(i,0,n) cin>>arr[i];
bool sorted=true;
iterate(i,1,n){
if(arr[i]<arr[i-1]) sorted=false;
}
if(sorted){
cout<<"YES"<<endl;
return;
}
ll maxi=*max_element(arr.begin(),arr.end());
iterate(i,1,n-1){
    if(arr[i]>arr[i-1] && arr[i]==maxi){
        cout<<"YES"<<endl;
        return;
    }
}
cout<<"NO"<<endl;
}
int main()
{
ll t;
cin>>t; 
while(t--){
solve();
}
    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;
#define vii vector<int> 
#define vll vector<long long>
#define pb push_back
#define ll long long
#define iterate(i,a,b) for(ll i=a;i<b;i++)
void solve(){
ll n; cin>>n;
vll arr(n); iterate(i,0,n) cin>>arr[i];
bool sorted=true;
iterate(i,1,n){
if(arr[i]<arr[i-1]) sorted=false;
}
if(sorted){
cout<<"YES"<<endl;
return;
}
ll maxi=*max_element(arr.begin(),arr.end());
iterate(i,1,n-1){
    if(arr[i]>arr[i-1] && arr[i]==maxi){
        cout<<"YES"<<endl;
        return;
    }
}
cout<<"NO"<<endl;
}
int main()
{
ll t;
cin>>t; 
while(t--){
solve();
}
    return 0;
}

Submission (verdict: Wrong answer on test 2):
/*
#       #      #   #######     #     #
#       #      #   #            #   #
#       #      #   #             # #
#       #      #   #              # 
#       #      #   #              # 
######  ########   #######        # 
*/
#include<bits/stdc++.h>
using namespace std;
#define vii vector<int> 
#define vll vector<long long>
#define pb push_back
#define ll long long
#define iterate(i,a,b) for(ll i=a;i<b;i++)
void solve(){
ll n; cin>>n;
vll arr(n); iterate(i,0,n) cin>>arr[i];
bool sorted=true;
iterate(i,1,n){
if(arr[i]<arr[i-1]) sorted=false;
}
if(sorted){
cout<<"YES"<<endl;
return;
}
ll maxi=*max_element(arr.begin(),arr.end());
iterate(i,1,n){
    if(arr[i]>arr[i-1] && arr[i]==maxi){
        cout<<"YES"<<endl;
        return;
    }
}
cout<<"NO"<<endl;
}
int main()
{
ll t;
cin>>t; 
while(t--){
solve();
}
    return 0;
}