Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include<iostream>

int ball[10];
int ls = 0, rs = 0;
bool res = true;

int main(){
	int n;
	std::cin >> n;
	for (int j = 0; j < n; j++){
		ls = 0, rs = 0, res = true;

		for (int i = 0; i < 10; i++)std::cin >> ball[i];

		for (int i = 0; i < 10; i++){
			int d1 = ball[i] - ls, d2 = ball[i] - rs;

			if (d1 > 0 && d2 > 0){
				if (d1 <= d2)ls = ball[i];
				else rs = ball[i];
			}
			else if (d1 > 0 && d2 < 0)ls = ball[i];
			else if (d1 < 0 && d2 > 0)rs = ball[i];
			else res = false;
		}

		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int ball[10];
int left=0,right=0;
bool dfs(int de){//??????????????§???????????????
	if(de==9)return true;
	if(left<ball[de]){
		left=ball[de];
		return dfs(de+1);
	}
	if(right<ball[de]){
		right=ball[de];
		return dfs(de+1);
	}
	return false;
}

int main(){
	int n;
	std::cin>>n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

C++: #include <iostream>

#define MAX 10
using namespace std;

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //cout << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    if(i!=count-1){
      cout << endl;
    }
  }
}

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

int main() {
    int n; cin >> n;  // ???????????????????????°
    
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[I]; // ??????????????????????????\???
        
        bool isYES = true;  // ???10???????????????????????????????????????
        int topB = 0, topC = 0;  // ???B?????????C???????????¨????????????
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a[10];
    for (int j=0;j<10;j++)
    cin >> a[j];
    int left,right; left = a[0];
    right = 0;
    for (int j=1;j<10;j++){
      if(a[j]<left && a[j]<right){
        cout << "NO" << endl; break;
      } else{
        if(j==9){
          cout << "YES" << endl; break;
        } else{
          if(a[j]>left && a[j]<right)
            left = a[j];
          else{
            if(a[j]<left && a[j]>right)
              right = a[j]; else{ if(left<right) right = a[j];
          else left = a[j];
          }
          }
          }
          }
    }
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int num[10];
bool check(int pos, int l, int r){
    if(pos >= 10) return true;
    if(l < num[pos]) if(check(pos+1,num[pos],r)) return true;
    if(r < num[pos]) if(check(pos+1,l,num[pos])) return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    rep(i,n){
        rep(j,10) cin >> num[j];
        if(check(0,-1,-1)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<cstdio>
const int maxn = 15;
int n,arr[maxn];
int main(){
    scanf("%d",&n);
    while(n--){
        for(int i = 0;i < 10;++i)scanf("%d",&arr[i]);
        int b = 0,c = 0,flag = 1;
        for(int i = 0;i < 10;++i){
            if(b>arr[i]&&c>arr[i]){
                flag = 0;
                break;
            }else if(b<arr[i] && c<arr[i]){
                if(b<c)c = arr[i];
                else b = arr[i];
            }else if(b < arr[i]){
                b = arr[i];
            }else c = arr[i];
        }
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int N;
    cin >> N;
    for(int index_n=0;index_n<N;index_n++){
        vector<int> V(10);
        rep(i,10) cin >> V[i];
        // left,right,next
        queue<pair<pair<int,int>,int> > Q;
        Q.push(mp(mp(V[0],0),1));
        bool ok = false;
        while(!Q.empty()){
            int left = Q.front().first.first;
            int right = Q.front().first.second;
            int next = Q.front().second;
            Q.pop();

            if(next == 10){
                ok = true;
                break;
            }
            if(V[next] > left){
                Q.push(mp(mp(V[next],right),next+1));
            }
            if(V[next] > right){
                Q.push(mp(mp(left,V[next]),next+1));
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}