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>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int cs = 0 ; cs < n ; cs++){
    int A[10];
    for(int i = 0 ; i < 10 ; i++) cin >> A[i];

    int B = 0, C = 0;
    bool flag = 1;
    
    for(int i = 0 ; i < 10 ; i++){
      if(A[i] > B) B = A[i];
      else if(A[i] > C) C = A[i];
      else flag = 0;
      
      if(B < C) swap(B, C);
    }
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int bl[10];
    bool ok[n];
    for (int i=0; i<n; i++) ok[i]=false;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++)
        {
            cin>>bl[j];
        }
        if ((bl[0]<bl[2] && bl[2]<bl[4] && bl[4]<bl[6] && bl[6]<bl[8]) && (bl[1]<bl[3] && bl[3]<bl[5] && bl[5]<bl[7] && bl[7]<bl[9])) ok[i]=true;
    }
    for (int i=0; i<n; i++)
    {
        if (ok[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10] = {0},b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
   int t;

    cout << "t:a:b" << endl;
    while(ball.empty() == false) {

      t = ball.back();
      ball.pop_back();
      // cout << t << endl;
      cout << t <<":"<< a[ac-1]<<":" << b[bc-1]<<endl;
      
      if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
	a[ac] = t;
	ac++;
      }
      else if(t > b[bc-1]) {
	b[bc] = t;
	bc++;
      } else break;
    }

    //  for(int i=0;i<ac;i++) cout << a[i] << endl;
    
    if(ac+bc == 11) cout << "YES" << endl << endl;
    else cout << "NO" << endl;

    ball.clear();

  }

  return 0;

}

C++: #include<iostream>
int main()
{
	int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		int b_back = 0, c_back = 0;
		bool is_OK = true;
		for (int j = 0; j < 10; j++)
		{
			int num;
			std::cin >> num;
			if (num < b_back && num < c_back)
			{
				is_OK = false;
			}
			else if (num > b_back && num < c_back)
			{
				b_back = num;
			}
			else if (num < b_back && num > c_back)
			{
				c_back = num;
			}
			else
			{
				if (b_back > c_back)
				{
					b_back = num;
				}
				else
				{
					c_back = num;
				}
			}
		}
		std::cout << (is_OK ? "YES" : "NO") << std::endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.push(ball[s]);
			dfs(s+1);
			A.pop();
		}
		if (ball[s] > B.top())
		{
			B.push(ball[s]);
			dfs(s+1);
			B.pop();
		}
	}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			while (!A.empty())
			{
				A.pop();
			} 
			while (!B.empty())
			{
				B.pop();
			}
			A.push(0);
			B.push(0);
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[12];
int n;
bool dfs(int b, int c, int ct) {
  if(ct == 10) return true;
  if(b < a[ct] && dfs(a[ct], c, ct + 1)) return true;
  if(c < a[ct] && dfs(b, a[ct], ct + 1)) return true;
  return false;
}

int main() {
  scanf("%d", &n);
  for(int j = 0; j < n; ++j) {
    for(int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    printf("%s\n", dfs(0, 0, 0) ? "YES" : "NO");
  }
  return 0;
}

C++: #include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int a,b,n,i,j,x[10];
    scanf("%d",&n);
for(j=0;j<n;j++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for(i=1;i<=9;i++){
if(x[i-1]>x[i]){
C.push(x[i]);
goto ccc;
}else{
	B.push(x[i]);
	goto bbb;
}
bbb:;
}
ccc:
for(j=i;j<9;j++){
if(B.top()<x[j+1]){
B.push(x[j+1]);
}else if(C.top()<x[j+1]){
	C.push(x[j+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }

C++: #include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n;
  cin>>n;
  REP(i,n){
    int x[10]={};
    bool f=true;
    REP(i,10)cin>>x[i];
    stack<int> B,C;
    B.push(x[0]);
    REP(i,9){
      if(x[i+1]<B.top()){
        if(C.empty()||(x[i+1]>C.top()&&!C.empty())){
          C.push(x[i+1]);
        }else{
          f=false;
          break;
        }  
      }else B.push(x[i+1]);
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
char a[maxn];
stack<int> p1 , p2;
bool dfs(int index , int n)
{
    for(int i = 0 ; i < 2 ; i ++){
        if(i == 1 && index < n){
            if(!p1.empty() && p1.top() > a[index]){
                return false;
            }else{
                p1.push(index);
                return dfs(index + 1 , n);
            }
        }
        else if(i == 2 && index < n){
            if(!p2.empty() && p2.top() > a[index]){
                return false;
            }else{
                p2.push(index);
                return dfs(index + 1 , n);
            }
        }
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }


        bool res = dfs(0 , n);
        /*
        for(int i = 0 ; i < n ;i ++){
            for(int j = 0 ; j < m ; j ++){
                cout << g[i][j] << " ";
            }
            cout << endl;
        }
        */
        if(res) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include<iostream>
using namespace std;
int arr[10];
bool dfs(int);
int l,r;
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)
			cin>>arr[i];
		l=r=0;
		if(dfs(0))
			cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}
bool dfs(int t){
	if(t==10) return 1;
	int t1=l;
	if(arr[t]>l){
		l=arr[t];
		if(dfs(t+1))
			return 1;
		l=t1;
	}
	int t2=r;
	if(arr[t]>r){
		r=arr[t];
		if(dfs(t+1))
			return 1;
		r=t2;
	}
	return 0;
}