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>
#include <stack>

using namespace std;

int main(void){
	int n = 0;
	int a[10];
	stack<int> b, c;
	bool r = true;

	scanf("%d", &n);
	for(int i=0;i<n;++i){
		for(int j=0;j<10;++j){
			scanf("%d", a+j);
		}
		b = stack<int>();
		c = stack<int>();
		r = true;

		for(int j=0;j<10;++j){
			if(b.empty() ||
				(c.empty() && b.top() < a[j])){
				b.push(a[j]);
			}else if(c.empty()){
				c.push(a[j]);
			}else if(b.top() < a[j] && c.top() < a[j]){
				if(b.top() > c.top()){
					b.push(a[j]);
				}else{
					c.push(a[j]);
				}
			}else if(b.top() < a[j]){
				b.push(a[j]);
			}else if(c.top() <a[j]){
				c.push(a[j]);
			}else{
				r = false;
				break;
			}
		}
		puts(r ? "YES": "NO");
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
const int inf=10000000;

int n,num[10];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		vector<int> l,r;
		l.push_back(-1*inf);
		r.push_back(-1*inf);
		bool ans=true;
		for(int j=0;j<10;j++){
			cin>>num[j];
		}
		l.push_back(num[0]);
		for(int j=1;j<10;j++){
			if(num[j]>l.back()&&num[j]>r.back()){
				if(l.back()>=r.back()) l.push_back(num[j]);
				else r.push_back(num[j]);
			}
			else{
				if(num[j]<=l.back()&&num[j]<=r.back()) ans=false;
				else{
					if(num[j]>l.back()) l.push_back(num[j]);
					else r.push_back(num[j]);
				}
			}
		}
		if(ans) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

using namespace std;
bool solve(deque<int> toAdd, deque<int> l,deque<int> r){
	if(toAdd.size()==0)return true;
	bool flag = false;
	if(l[l.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		l.push_back(j);
		flag = flag || solve(toAdd,l,r);
		//back to original problem
		toAdd.push_front(j);
	        l.pop_back();
	}
	if(flag)return true;
	if(r[r.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		r.push_back(j);
		flag = flag || solve(toAdd,l,r);
	}
	return flag;
}
int main(){
	int n;
	cin>>n;
	while(n-->0){
		deque<int> balls;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			balls.push_back(j);
		}
		deque<int> sol;sol.push_back(0);
		if(solve(balls,sol,sol)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int time;
	cin>>time;
	int ball[10];
	vector<int> line1;
	vector<int> line2;
	for(int i2=0;i2<time;++i2){
		for(int i=0;i<10;++i){
			cin>>ball[i];
		}
		line1.push_back(ball[9]);
		for(int i=8;i>=0;--i){
			if(line1.back()>ball[i])line1.push_back(ball[i]);
			else if(line2.empty()||line2.back()>ball[i])line2.push_back(ball[i]);
			else {
				cout<<"NO"<<endl;
				goto NO;
			}
		}
		cout<<"YES"<<endl;
		NO:;
	}
	return 0;
}

C++: #include<stdio.h>
main(){
    int x[10],y[10],z[10],i,j,n,cz,cy,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        tmp=0;
        cy=0;cz=0;
        for(j=0;j<10;j++){
        scanf("%d",&x[j]);
        z[j]=0;y[j]=0;
        }
        for(j=0;j<10;j++){
        if(x[j]>=y[cy-1*(cy>0)])
        y[cy++]=x[j];
        else if(x[j]>=z[cz-1*(cz>0)])
        z[cz++]=x[j];
        else
        tmp=1;
        }
        if(tmp==1)
        printf("NO\n");
        else
        printf("YES\n");
        for(j=0;j<10;j++)
        printf("%d ",y[j]);
        printf("\n");
        for(j=0;j<10;j++)
        printf("%d ",z[j]);
        printf("\n");
    }
}

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

bool able;
void rec(queue<int> A,stack<int> B,stack<int> C){
	if( A.empty() ){
		able = true;
		return;
	}
	
	int tp = A.front();
	
	A.pop();
	
	if(tp > B.top() ){
	 	B.push(tp);
	 	rec(A,B,C);
	}
	if(tp > C.top() ){
	 	C.push(tp);
	 	rec(A,B,C);
	}
	
	return ;
}
int main(){
	int n,t;
	stack<int>a,b;
	a.push(0);
	b.push(0);
	cin >> n;
	while(n--){
		queue<int>input;
			able = false;
		for(int i=0;i<10;i++){
			cin >> t;
			input.push(t);
		}
		rec(input,a,b);
		cout << (able?"YES":"NO") << endl;
	}
}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
int in[10];
bool dfs(int n,vector<int> l,vector<int> r){
  if(n==10)return true;
  if(l.size()==0 or in[n]>l[l.size()-1]) 
  {
    l.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  if(r.size()==0 or in[n]>r[r.size()-1] ){
    r.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  return false;
  }
int main(){
  int d;
  cin>>d;
  for(int dd=0;dd<d;dd++){
    for(int i=0;i<10;i++){
      cin>>in[i];
    }
    vector<int> l,r;
    if(dfs(0,l,r )) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
  
  }
  return 0;
}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() != true && C.empty() != true) {
				if (B.top() > k && C.top() > k) {
					ans = "NO";
					break;
				}
			}
			else if (B.empty() == true)
				B.push(k);
			else if (B.top() < k)
				B.push(k);
			else if (B.top() > k)
				C.push(k);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<stdio.h>

#include<string.h>

int a[13],vis[13],flag;

void dfs(int x,int l,int r)

{

    int i;

    if(x==11)return; 

    if(flag)return ;

    if(a[x]>l)dfs(x+1,a[x],r);

    else  if(a[x]>r)dfs(x+1,l,a[x]);

    else  {flag=1;return;}

  

}

int main()

{

int T,i,j,k;

scanf("%d",&T);

while(T--)

{

flag=0;

for(i=1;i<=10;i++)

scanf("%d",&a[i]);

memset(vis,0,sizeof(vis));

dfs(1,0,0);

if(flag)printf("NO\n");

else printf("YES\n");

}

return 0;

}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int i, lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}