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>
using namespace std;

int main()
{
	int N;
	cin>>N;
	for(int n=0; n<N; n++){
		int b = 0;
		int c = -1;
		bool dameflg = false;
		for(int i=0; i<10; i++){
			int a;
			cin>>a;
			if(b > c){
				if(b > a){
					if(c > a){
						dameflg = true;
					} else {
						c = a;
					}
				} else {
					b = a;
				}
			} else {
				if(c > a){
					if(b > a){
						dameflg = true;
					} else {
						b = a;
					}
				} else {
					c = a;
				}
			}
		}
		if(dameflg) cout<<"NO";
		else        cout<<"YES";
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <queue>

using namespace std;

queue<int> A;
queue<int> B;
int num[10];

bool DFS(int i) {
	if (i < 10)
	{
		int pos = i;
		int temp = num[i];
		for (int j = i; j < 10; j ++)
		{
			if (num[j] < temp)
			{
				pos = j;
				break;
			}
		}
		for (int k = i; k < pos; k++)
		{
			if (A.empty())
			{
				A.push(num[k]);
			}
			else
			{
				int tempNum = A.back();
				if (num[k] > tempNum)
				{
					A.push(num[k]);
				}
				else
				{
					return false;
				}
			}
		}
		if (B.empty())
		{
			B.push(num[pos]);
		}
		else
		{
			int temp_B = B.back();
			if (temp_B < num[pos])
			{
				B.push(num[pos]);
			}
			else
			{
				return false;
			}
		}
		DFS(pos+1);
	}
	return true;
}
int main() {
	int n;
	while (cin >> n)
	{
		while (n-- > 0)
		{
			for (int i = 0; i < 10; i++)
			{
				cin >> num[i];
			}
			if (DFS(0))
			{
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <stack>
using namespace std;
#define N 10003
#define PI 3.14159265358979323
#define INF 0x3f3f3f3f
#define MOD 100000007
#define ll long long
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
int n,a[N];
int gp[11];
int W,H;
int cnt=0;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int us[11];
void dfs ( int x )
{
	int i;
	int nx,ny;
	i=1;
	while ( i<10&&(us[x+i]==1||gp[x+i]<=gp[x]) )
	i++;
	
	if ( x+i<10&&gp[x+i]>gp[x]&&us[x+i]==0 )
	{
		us[x+i]=1;
		dfs(x+i);
	}

}

//template < class T> void read ( T &x ){	char c;int sign=1;x=0;while ( c=getchar(),(c>'9'||c<'0')&&c!='-') ;if ( c=='-' ){sign=-1;}else x=c-'0';while ( c=getchar(),c<='9'&&c>='0' ){x=x*10+c-'0';}x=x*sign;}
int main ( )
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i,j;
	int f;
	cin>>n;
	while (n-- )
	{
		f=0;
		memset ( us,0,sizeof(us));
		for ( i=0;i<10;i++ )
		{
			cin>>gp[i];
		}
		cnt=0;
		
		for ( i=0;i<10;i++ )
		{
			if ( us[i]==0 )
			{
				cnt++;
				us[i]=1;
				dfs(i);
			}
		}
		
		if ( cnt==2 )
		f=1;
		
		
		if ( f )
		printf("YES\n");
		else
		printf("NO\n");
		
		//printf( "%d\n",cnt); 
		
	} 
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include<stack>
#include<vector>

using namespace std;
int t[11];
vector<int>a;
vector<int>b;
int aa,bb;
bool solve()
{
      for(int i = 0 ; i< 1<<10 ;i++)
      {
          a.clear(),aa=0;
          b.clear(),bb=0;
        for(int j = 0 ; j < 10 ; j++)
        {
            if(i&(1<<j))
            a.push_back(t[j]);
            else
            b.push_back(t[j]);

        }
        int l1=a.size();
        int l2=b.size();
      for(int i=0;i<(a.size()-1);i++)
      {
         if(a[i]>a[i+1])
              
          {
                 aa=1;break;
          }

      }

        for(int i=0;i<l2-1;i++)
      {
          if(b[i]>b[i+1])
          {
              bb=1;break;
          }

      }

      if(aa==0&&bb==0)
      {
          return true;
      }

    }

        return false;


}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        a.clear();aa=0;
        b.clear();bb=0;
        memset(t,0,sizeof(t));
        for(int i = 0 ; i < 10 ; i++)
        {
           scanf("%d",&t[i]);
        }

        if(solve())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

   }
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scor (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(left.top() < a[c]){
		left.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(right.top() < a[c]){
		right.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) left.pop();
	else right.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	FOR(n){
		left.push(0);
		right.push(0);
		for(i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
		while(left.empty()) left.pop();
		while(right.empty()) right.pop();
	}
	return 0;
}

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

using namespace std;
const int maxn = 11;
int num[maxn];

int main()
{
    int ite=0;
    scanf("%d", &ite);
    while(ite--)
    {
        for(int i=0; i<10; ++i)
        {
            scanf("%d", &num[i]);
        }

        stack<int> a, b;

        a.push(0);
        b.push(0);
        for(int i=0; i<10; ++i){
            int dif1 = num[i] - a.top(), dif2 = num[i]-b.top();
            if(dif1<0 && dif2<0) {
                printf("NO\n");
                return 0;
            }
            else if(dif1>0 && dif2>0){
                if(a.top()<b.top()) b.push(num[i]);
                else a.push(num[i]);
            }
            else{
                if(dif1>0) a.push(num[i]);
                else b.push(num[i]);
            }
        }

        printf("YES\n");
    }
    return 0;
}