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(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=1;B[0]=0;b1=0;c1=0;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=0;;j++){
                cout<<bo[j]<<" ";
            if(j==0)B[0]=bo[0];
        if(B[l]<bo[j]){
            b1=1;
            B[l]=bo[l];
            l++;
            cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k]=bo[j];
            cout<<"3\n";
        }else{
            B[l+1]=bo[j];
            l++;
            cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int s[10]={0};
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0,b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
int T,a[15],dp[15];
int main(){
	scanf("%d",&T);
	while(T--){
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=10;i++) scanf("%d",&a[i]);
		for(int i=1;i<=10;i++){
			*lower_bound(dp+1,dp+11,a[i],greater<int>()) = a[i];
		}
		if(dp[3] != 0) puts("NO");
		else puts("YES");
	}
	return 0;
}

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

using namespace std;



int main()
{
        int num = 0, tmp_right, tmp_left, ispush = 0, i, j;
        std::array< int, 10 > ar;
        std::vector< int > right, left;
        cin >> num;

        for ( j = 0 ; j < num ; j = j + 1 )
        {
                for ( i = 0 ; i < 10 ; i = i + 1 )
                {
                        cin >> ar[i];
                        ispush = 0;
                        if ( right.size() == 0 )
                        {
                                ispush = 1;
                                right.push_back( ar[i] );
                        }
                        else if ( right.size() != 0 )
                        {
                                tmp_right = right.back();
                                if ( tmp_right < ar[i] )
                                {
                                        right.push_back( ar[i] );
                                        ispush = 1;
                                }
                        }

                        if ( ispush == 0 )
                        {
                                if ( left.size() == 0 )
                                {
                                        ispush = 1;
                                        left.push_back( ar[i] );
                                }
                                else if ( left.size() != 0 )
                                {
                                        tmp_left = left.back();
                                        if ( tmp_left < ar[i] )
                                        {
                                                ispush = 1;
                                                left.push_back( ar[i] );
                                        }
                                }
                        }

                        if ( ispush == 0 )
                        {
                                cout << "NO" << endl;
                                break;
                        }
                        else
                        {
                                ispush = 0;
                        }
//                      cout << i << endl;
                        if ( i == 9 )
                        {
                                cout << "YES" << endl;
                        }


                }
                right.clear();
                left.clear();

        }


        return 0;
}

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

typedef vector<int> vi;

#define pb push_back

bool dfs(vi& a, int i, int b, int c)
{
  if (i == 10)
    return true;
  if (b < a[i] && dfs(a, i+1, a[i], c))
    return true;
  if (c < a[i] && dfs(a, i+1, b, a[i]))
    return true;
  return false;
}

int main(int argc, char **argv)
{
  int n, x;
  cin >> n;
  while (n--) {
    vi a;
    for (int i = 0; i < 10; i++) {
      cin >> x;
      a.pb(x);
    }
    if (dfs(a, 0, 0, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
int a;
int b;
int n;
int c;
int d;
int e;
int f;
c=0;
while(c<n){
f=0;
a=0;
b=0;
d=0;
while(d<10){
cin >>e;
if(e>a&&a>b){a=e;}
else if(e>b&&b>a){b=e;}
else if(e>a){a=e;}
else if(e>b){b=e;}
else{f=1; break;}
d=d+1;}
if(f==0){cout <<"YES"<<endl;}
if(f==1){cout <<"NO"<<endl;}
c=c+1;}}

C++: // Aoj 0033: Ball
#include<bits/stdc++.h>
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;

const int N=110,M=20010;
int h[N],to[M],nexp[M],p=1;
inline void init_list(){mset(h,0),mset(nexp,0),p=1;}
inline void ins(int a,int b){
    nexp[p]=h[a],h[a]=p,to[p]=b,p++;
}
int arr[N];
int col[N];
bool imp;
void dfs(int x,int ncol){
    col[x]=ncol;
    for(int u=h[x];u;u=nexp[u]){
        if(col[to[u]] == col[x]) imp=1;
        if(imp) return;
        if(!col[to[u]]) dfs(to[u],ncol^1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<10;i++) cin>>arr[i];
        for(int i=0;i<10;i++)
        for(int j=i+1;j<10;j++)
            if(arr[i]>arr[j]) ins(i,j),ins(j,i);
        mset(col,0), imp=0;
        for(int i=0;i<10;i++)
            if(!col[i]) dfs(i,2);
        if(imp) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<int> A = {-1};
vector<int> B = {-1};
int num[10];
bool flag = false;
void push(int i)
{
	if (i == 10)
		flag = true;
	else
	{
		if (A.back() < num[i])
		{
			A.push_back(num[i]);
			push(i + 1);
			A.pop_back();
		}
		if (B.back() < num[i])
		{
			B.push_back(num[i]);
			push(i + 1);
			B.pop_back();
		}
	}
}
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		flag = false;
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (flag == true)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}