Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

int n;
int a[11];
//int r, l;

// bool dfs(int i) {
//     if (i == 9) return a[i] > r || a[i] > l;
//     if (a[i] > r) {
//         r = a[i];
//     }
//     if (a[i] > l) {
//         l = a[i];
//     }
//     if (dfs(i+1)) return true;
//     return false;
// }

bool dfs(int i, int r, int l) {
    if (i == 9) return a[i] > a[r] || a[i] > a[l];
    if (dfs(i+1, max(a[i+1], r), l)) return true;
    if (dfs(i+1, r, max(a[i+1], l))) return true;
    return false;
}

void solve() {
    if (dfs(0,0,0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}

C++: #include <iostream>
using namespace std;
 
int a[10];
int n;
 
bool dfs(int i,int left,int right){
    if(i==10) return true;
    if(a[i]>left){
        if(dfs(i+1,a[i],right)) return true;
    }
    if(a[i]>right){
        if(dfs(i+1,left,a[i])) return true;
    }
    return false;
}
 
void solve(){
    for(int i=0;i<10;i++) cin >> a[i];
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}
 
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        solve();
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int bfs(int, int, int);
int a[10];
int main(void){

	int n;

	cin >> n;
	for (int n_count = 0; n_count < n; n_count++){

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

			cin >> a[i];
		}

		if (bfs(0, 0, 0) == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

int bfs(int i, int l, int r){

	int ans = 0;

	if (i == 10)
		ans = 1;

	if (l < a[i])
		ans = bfs(i + 1, a[i], r);

	if (r < a[i])
		ans = bfs(i + 1, l, a[i]);

	return ans;
}

C++: //???1601-2 ????±????(616342287) 12:28:09
#include <iostream>
#include <fstream>
#include <stack>
#include <vector>
#include <cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
  if(x==10)
  {
    flag=1;
    return;
  }
  if(a[x]<b[y]&&a[x]<c[z])
      return;
  if(a[x]>b[y])
  {
      b[y+1]=a[x];
      dfs(x+1,y+1,z);
      b[y+1]=0; 
  }
  if(a[x]>c[z])
  {
      c[z+1]=a[x];
      dfs(x+1,y,z+1);
      c[z+1]=0; 
  }
}
int main()
{
//  freopen("3.txt","r",stdin);
  int n;
  cin >> n;
  while(n--)
  {
  flag=0;
  memset(b,0,sizeof(b));
  memset(c,0,sizeof(c));
  for(int i=0;i<10;i++)
      cin >> a[i];
  dfs(0,0,0);
  if(flag)
      cout << "YES" << endl;
  else
      cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, count, before;

  cin >> n;

  for(int i = 0; i < n; i++){
    count = 0;
    before = 0;
    for(int j = 0; j < 10; j++){
      cin >> num;
      if(num < before){
        count++;
        if(count >= 2){
          cout << "NO" << endl;
          break;
        }
      }else{
        count = 0;
      }
      before = num;
    }
    if(count < 2) cout << "YES" << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int bTop = 0, cTop = 0;
        for (int j = 0; j < 10; j++) {
            int input;
            cin >> input;
            if (bTop >= cTop) {
                if (input > bTop) {
                    bTop = input;
                } else if (input > cTop) {
                    cTop = input;
                } else {
                    cout << "NO" << endl;
                    break;
                }
            } else {
                if (input > cTop) {
                    cTop = input;
                } else if (input > bTop) {
                    bTop = input;
                } else {
                    cout << "NO" << endl;
                    break;
                }
            }
            if (j == 9) {
                cout << "YES" << endl;
            }
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long ll;


int a[10];

bool put(int cur,int lt, int rt) {
	if (cur == 10)
		return true;
	if (a[cur] < lt && a[cur] < rt)
		return false;
	bool lres= false,rres=false;
	if( a[cur] > lt) {
		lres = put(cur + 1, a[cur], rt);
	}
	if( a[cur] > rt) {
		rres = put(cur + 1, lt, a[cur]);
	}
	if (lres || rres)
		return true;
	else
		return false;
}

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		if (put(0, 0, 0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[10];
bool ans;

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) {
         cin >> a[i];
      }
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        while(!a.empty()){
            a.pop();
        }
        while(!b.empty()){
            b.pop();
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}