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>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;


int saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return 1;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return 0;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==1)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n;
    bool flag = true;
    vector<int> b, c;
    b.push_back(0);
    c.push_back(0);
    vector<int> ::iterator b_it=b.begin(), c_it=c.begin();

    cin>> n;
    while(n--, n!=-1){
        for(int i=0; i<10; i++){
            cout<<i << flag <<endl;
            if(flag){
                int num;
                cin>> num;
                if(num>*b_it){
                    b.push_back(num);
                    b_it = b.end()-1;
                }else if(num>*c_it){
                    c.push_back(num);
                    c_it = c.end()-1;
                }else{
                    flag = false;
                }
            }
        }
        if(flag){
            cout<< "YES"<< endl;
        }else{
            cout<< "NO"<< endl;
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n;
  for(int i=0;i<t;i++){
    int h = 0,b = 0,c = 0;
    for(int j=0;j<10;j++){
      cin >> n;
      if(b==0) b = n;
      else if(b>c&&b<n) b = n;
      else if(c>b&&c<n) c = n;
      else if(b>c&&b>n&&c<n) c = n;
      else if(c>b&&c>n&&b<n) b = n;
      else if(b>n&&c>n){
	cout << "NO" << endl;
	h = 1;
	break;
      }
    }
    if(h==0) cout << "YES" << endl;
  }
  return 0;
}

C++: /*
P135
AOJ 0033 Ball
http://judge.u-aizu.ac.jp/onlinejudge/index.jsp

*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int W, H;
char board[110][110];
int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}



void solve1()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;

}

void solve2()
{
    if(dfs2(0))
        printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}

C++: #include <iostream>

using namespace std;

const int N = 10;

int main()
{
	int n;

	cin >> n;
	while (n--) {
		bool ans = true;
		int a, b = -1, c = -1;
		for (int i = 1; i <= N; i++) {
			cin >> a;
			if (ans) {
				if (a > b)
					b = a;
				else if (a > c)
					c = a;
				else
					ans = false;
			}
		}

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

C++: #include <iostream>

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 lines;

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

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int f = 0;
  int b = 0 ,c = 0;
  cin >> n;
  while(n--){
    f=0;
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b < a)b = a;
      else if(c < a)c = a;
      else {
	f = 1;	
      }  
    }
    if(f == 1)cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

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

int main(){
    int x;
    std::cin>>x;
    for(int i=0;i<x;++i){
        std::vector<int> vec(10);
        for(int l=0;l<10;++l){
            std::cin>>vec[l];
        }
        std::vector<std::vector<int> > vec2(2);
        vec2[0].push_back(vec[0]);
        for(int l=1;l<vec.size();++l){
            if(l==1){
                if(vec2[0][0]<vec[1]){
                    vec2[0].push_back(vec[1]);
                }else vec2[1].push_back(vec[1]);
            }else{
                if(vec[l]>vec2[0][vec2[0].size()-1]){
                    if(vec2[1].size()!=0&&vec2[1][vec2[1].size()-1]>vec[l]){
                        if(vec2[0][vec2[0].size()-1]>vec2[1][vec2[1].size()-1])vec2[0].push_back(vec[l]);
                        else vec2[1].push_back(vec[l]);
                    }else{
                        vec2[0].push_back
                    }
                }else{
                    if(vec2[1].size()!=0?vec[l]>vec2[1][vec2[1].size()-1]:true){
                        vec2[1].push_back(vec[l]);
                    }else{
                        std::cout<<"NO"<<std::endl;
                        goto cont;
                    }
                }
            }
        }
        std::cout<<"YES"<<std::endl;
    cont:;
    }
    return 0;
}

C++: #include<stdio.h>
int a[10];
int bstack[10];
int btop;
int cstack[10];
int ctop;
int dfs(int i)
{
    bool b1=false,b2=false;
    if(i==10)
        return true;
    if(btop==-1 || bstack[btop]<a[i])
    {
        btop++;
        bstack[btop]=a[i];
        b1=dfs(++i);
        btop--;
    }
    if(ctop==-1 || cstack[ctop]<a[i])
    {
        ctop++;
        cstack[ctop]=a[i];
        b2=dfs(++i);
        ctop--;
    }
    return b1 || b2;
}
int main()
{
    int n;
    while(n--)
    {
        for(int i=0;i<10;i++)
        {
            scanf("%d",&a[i]);
        }
        btop=-1;
        ctop=-1;
        if(dfs(0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}