ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: Java 21

Previous submission (verdict: Wrong answer on test 8):
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubsequenceUpdate {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int tests = Integer.parseInt(scanner.nextLine());
    while (tests > 0){
      int n = scanner.nextInt();
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      int[] arr = new int[n];
      for (int i = 0; i < arr.length; i++){
        arr[i] = scanner.nextInt();
      }

      ArrayList<Integer> toL = new ArrayList<>();
      ArrayList<Integer> toR = new ArrayList<>();
      for (int i = 0; i < r; i++){
        toR.add(arr[i]);
      }
      for (int i = l - 1; i < n; i++){
        toL.add(arr[i]);
      }

      Collections.sort(toL);
      Collections.sort(toR);

      int sumOne = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumOne += toL.get(i);
      }

      int sumTwo = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumTwo += toR.get(i);
      }

      System.out.println(Math.min(sumTwo, sumOne));
      tests--;
    }
  }
}


Submission (verdict: Wrong answer on test 8):
import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;



public class SubsequenceUpdate {

  public static void main(String[] args){

    Scanner scanner = new Scanner(System.in);

    int tests = Integer.parseInt(scanner.nextLine());

    while (tests > 0){

      int n = scanner.nextInt();

      int l = scanner.nextInt();

      int r = scanner.nextInt();

      long[] arr = new long[n];

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

        arr[i] = scanner.nextLong();

      }



      ArrayList<Long> toL = new ArrayList<>();

      ArrayList<Long> toR = new ArrayList<>();

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

        toR.add(arr[i]);

      }

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

        toL.add(arr[i]);

      }



      Collections.sort(toL);

      Collections.sort(toR);



      int sumOne = 0;

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

        sumOne += toL.get(i);

      }



      int sumTwo = 0;

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

        sumTwo += toR.get(i);

      }



      System.out.println(Math.min(sumTwo, sumOne));

      tests--;

    }

  }

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    int c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    int a = min(c2,8);
    int b = min(c3,8);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            int s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    ll c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    ll a = min(c2,8LL);
    ll b = min(c3,8LL);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            ll s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    ll c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    ll a = min(c2,10LL);
    ll b = min(c3,10LL);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            ll s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    string s;
    cin >> s;
    int c2 = 0,c3 = 0;
    ll sum = 0;
    for (auto& c:s) {
        int rem = c - '0';
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
    }
    int a = min(c2,8);
    int b = min(c3,8);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            ll s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    ll c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    ll a = min(c2,8LL);
    ll b = min(c3,8LL);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            ll s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    ll c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    ll a = min(c2,10LL);
    ll b = min(c3,10LL);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            ll s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

// Global Variable Declaration


void solve(){
    ll n;
    cin >> n;
    if (n%9 == 0) {
        cout << "YES\n";
        return;
    }
    ll back = n;
    int c2 = 0,c3 = 0,sum = 0;
    while (back > 0) {
        int rem = back%10;
        sum += rem;
        if (rem == 2) c2++;
        else if (rem == 3) c3++;
        back /= 10;
    }
    int a = min(c2,8);
    int b = min(c3,8);
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            int s = sum + i*2 + j*6;
            if (s%9 == 0) {
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int _t;cin >> _t;while(_t--)
    solve();
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx = i;
        int val = s[i]-'0';
        for(int j=i;j<n;j++){
            if(s[j]=='0'){
                continue;
            }
            if(s[j]-'0' -(j-i) > val){
                val = s[j]-'0'-(j-i);
                idx = j;
            }
        }
        s[idx]=val+'0';
        while(idx>i){
            swap(s[idx],s[idx-1]);
            idx--;
        }
    }
        cout<<s<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        int idx = i;
        int val = s[i]-'0';
        for(int j=i;j<min(i+10,n);j++){
            if(s[j]=='0'){
                continue;
            }
            if(s[j]-'0' -(j-i) > val){
                val = s[j]-'0'-(j-i);
                idx = j;
            }
        }
        s[idx]=val+'0';
        while(idx>i){
            swap(s[idx],s[idx-1]);
            idx--;
        }
    }
    cout<<s<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx =-1;
        int val =INT_MIN;
        for(int j=0;j<s.size();j++){
            if((s[j]-'0')-j >val){
                val = (s[j]-'0')-j;
                idx =j;
            }    
        }
        cout<<val;
        s.erase(s.begin()+idx);
    }
    cout<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx = i;
        int val = s[i]-'0';
        for(int j=i;j<n;j++){
            if(s[j]=='0'){
                continue;
            }
            if(s[j]-'0' -(j-i) > val){
                val = s[j]-'0'-(j-i);
                idx = j;
            }
        }
        s[idx]=val+'0';
        while(idx>i){
            swap(s[idx],s[idx-1]);
            idx--;
        }
    }
        cout<<s<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx =-1;
        int val =INT_MIN;
        for(int j=0;j<s.size();j++){
            if((s[j]-'0')-j >val){
                val = (s[j]-'0')-j;
                idx =j;
            }    
        }
        ans[i]=val;
        s.erase(s.begin()+idx);
    }
    for(int i=0;i<n;i++){
        cout<<ans[i];
    }
    cout<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx =-1;
        int val =INT_MIN;
        for(int j=0;j<s.size();j++){
            if((s[j]-'0')-j >val){
                val = (s[j]-'0')-j;
                idx =j;
            }    
        }
        cout<<val;
        s.erase(s.begin()+idx);
    }
    cout<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fe first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)

const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int idx =-1;
        int val =INT_MIN;
        for(int j=0;j<s.size();j++){
            if((s[j]-'0')-j >val){
                val = (s[j]-'0')-j;
                idx =j;
            }    
        }
        ans[i]=val;
        s.erase(s.begin()+idx);
    }
    for(int i=0;i<n;i++){
        cout<<ans[i];
    }
    cout<<endl;
}
int main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
// February 6

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

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

        int flag = 1;
        for(int i=0;i<n-2;i++) {
            if(a[i] >= a[i+1] && a[i+1] >= a[i+2]) {
                flag = 0;
                cout << "NO" << endl;
                break;
            }
        }

        if(flag) {
            cout << "YES" << endl;
        }
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
// February 6

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        
        if(n == 1) {
          cout << "YES" << endl;
          continue;
        }
        
        if(n == 2) {
          cout << ((a[0]<=a[1])?"YES":"NO") << endl;
          continue;
        }
        
        if(a[0]>a[1]) {
          cout << "NO" << endl;
          continue;
        }
        
        int flag = 1;
        for(int i=0;i<n-2;i++) {
            if(a[i] >= a[i+1] && a[i+1] >= a[i+2]) {
                flag = 0;
                cout << "NO" << endl;
                break;
            }
        }

        if(flag) {
            cout << "YES" << endl;
        }
    }
    return 0;
}


Submission (verdict: Accepted):
// February 6

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        
        for(int i=0;i<n-1;i++) {
          int m = min(a[i], a[i+1]);
          a[i] -= m;
          a[i+1] -= m;
        }
        
        int flag = 1;
        for(int i=0;i<n-1;i++) {
          if(a[i] > a[i+1]) flag = 0;
        }
        
        cout << (flag?"YES":"NO") << endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
// February 6

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        
        if(n == 1) {
          cout << "YES" << endl;
          continue;
        }
        
        if(n == 2) {
          cout << ((a[0]<=a[1])?"YES":"NO") << endl;
          continue;
        }
        
        int flag = 1;
        for(int i=0;i<n-2;i++) {
            if(a[i] >= a[i+1] && a[i+1] >= a[i+2]) {
                flag = 0;
                cout << "NO" << endl;
                break;
            }
        }

        if(flag) {
            cout << "YES" << endl;
        }
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
// February 6

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        
        if(n == 1) {
          cout << "YES" << endl;
          continue;
        }
        
        if(n == 2) {
          cout << ((a[0]<=a[1])?"YES":"NO") << endl;
          continue;
        }
        
        if(a[0]>a[1]) {
          cout << "NO" << endl;
          continue;
        }
        
        int flag = 1;
        for(int i=0;i<n-2;i++) {
            if(a[i] >= a[i+1] && a[i+1] >= a[i+2]) {
                flag = 0;
                cout << "NO" << endl;
                break;
            }
        }

        if(flag) {
            cout << "YES" << endl;
        }
    }
    return 0;
}