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 <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	for (i = 0; i < 10; i++){
		tube2[i] = 0;
	}
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j + 1] = tubeM[i];
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("OK\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

C++: #include<iostream>

using namespace std;

int main(void){
	int a[11],fir,n;
	int i;
	cin>>n;
	while(c--){
		int sec = 0;
		for(i=0;i<10;i++){
			cin>>a[i];
		}
		fir=a[0];
		for(i=1;i<10;i++){
			if(fire<a[i])fir=a[i];
			else if(sec<a[i])sec=a[i];
			else break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;

}

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

int main() {
	int n, a;
	vector<int> A;
	vector<vector<int>> AA;
	cin >> n;
	bool check[100] = { 1 };
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			A.push_back(a);
		}
		AA.push_back(A); A.clear();
	}
	for (int i = 0; i < AA.size(); i++) {
		int b = 0, c = 0; check[i] = 1;
		for (int j = 0; j < AA[i].size(); j++) {
			if (b >= c) {
				if (AA[i][j] > b)b = AA[i][j];
				else {
					if (AA[i][j] > c)c = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
			else {
				if (AA[i][j] > c)c = AA[i][j];
				else {
					if (AA[i][j] > b)b = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
		}
	}
	for (int i = 0; i < AA.size(); i++) {
		if (check[i])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int loop,ball,hidari,migi;
int main(){
  cin>>loop;
  for(int i=0;i<loop;i++){
    hidari=migi=0;
    for(int j=0;j<10;j++){
      cin>>ball;
      if(ball<=migi&&ball<=hidari){cout<<"NO"<<endl;j=10;}
      if(hidari>migi){
	if(ball>hidari)hidari=ball;
	else migi=ball;
      }
      else{
	if(ball>migi)migi=ball;
	else hidari=ball;
	}
      if(j==9){
	cout<<"YES"<<endl;
      }
    }
  }
}

C++: /*************************************************************************
    > File Name: aoj0033.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017??´06???21??\ ????????? 19??¶29???08?§?
 ************************************************************************/

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

int n , ball[10] , left_back , last_lb , right_back , last_rb ;
bool ok;

void DFS(int num){
	if( ok || num > 10 )	return;
	if( num == 10 ){
		ok = true;	return;
	}
	if( ball[num] >= left_back ){
		last_lb = left_back;
		left_back = ball[num];
		DFS(num+1);	
		left_back = last_lb;
	}
	if( ball[num] >= right_back ){
		last_rb = right_back;
		right_back = ball[num];
		DFS(num+1);	
		right_back = last_rb;
	}
}
int main(){
	scanf("%d",&n);
	while(n--){
		for(int i = 0 ; i < 10 ; i++){
			scanf("%d",&ball[i]);
		}
		ok = false;	left_back = right_back = last_lb = last_rb = 0;
		DFS(0);
		if(ok)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
int a[10];
int main(){
  IOS;
  int n; cin >> n;
  // rep(k,n){
  //   rep(i, 10)scanf("%d", &a[i]);
  //   rep(i,1<<10){
  //     stack<int>s[2];
  //     rep(j, 10){if(s[(i>>j)&1].empty() || a[j] > s[(i>>j)&1].top())s[(i>>j) & 1].push(a[j]);cout<<s[0]<<" "<<s[1]<<endl;}
  //     if(s[0].size()+s[1].size()==10){cout << "YES";break;}
  //     if(i==(1<<10)-1){cout<<"NO"<<endl;break;}
  //   }
  //
  // }
  int b[10];
  rep(j,n){
    int flag=0;
    rep(i,10){
      cin>>b[i];
    }
    stack<int>ta, tb;
    ta.push(b[0]);
    tb.push(0);
    repn(k,9){
      if(b[k]>ta.top()){ta.push(b[k]);}
      else if(b[k]>tb.top()){tb.push(b[k]);}
      else{ flag++;break;}
    }
    if(flag==0)cout<<"YES"<<endl;
    else{cout<<"NO"<<endl;}
  }
  return 0;
}

C++: #include <stdio.h>

int main(void)
{
    int a[10];
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        bool ans = false;
        for (int i = 0; i < 10; i++){
            scanf("%d", a + i);
        }
        for (int i = 0; i < (1 << 10); i++){
            int stack[2];
            int j;
            stack[0] = stack[1] = 0;
            for (j = 0; j < 10; j++){
                int k = ((i >> j) & 1);
                if (stack[k] < a[j]){
                    stack[k] = a[j];
                }
                else {
                    break;
                }
            }
            if (j == 10){
                ans = true;
                break;
            }
        }
        puts(ans ? "YES" : "NO");
    }

    return (0);
}

C++: #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int a[13],b[13],c[13],flag;
void dfs(int step,int bn,int cn)
{
    if(step==10){
        flag=1;
        return ;
    }
    if(flag) return ;
    if(a[step]>b[bn-1]){
    	b[bn]=a[step];
    	dfs(step+1,bn+1,cn);
	}
    if(a[step]>c[cn-1]){
    	c[cn]=a[step];
    	dfs(step+1,bn,cn+1);
	}
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        flag=0;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        dfs(0,1,1);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

	int n;
	cin >> n;
	bool test = false;
	
	while( n-- ) {
		
		int A[10] = {0};
		int B[10] = {0};
	
		int j = 0, k = 0;
		int a;
		
		for(int i=0;i<10;i++) {
			
			cin >> a;
			
			if( a > A[j] ) {
				
				A[j+1] = a;
				j++;
				
			}
			else {
				if( a > B[k]) {
					
					B[k+1] = a;
					k++;
					
				}
			}
		}
		if ( j + k == 10)
			cout << "YES\n";
		else
			cout << "NO\n"; 
		
	}
	
    return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}