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

int main()
{
    int Atop=0, Btop=0, n, ball;
    cin >> n;
    while (n-->0) {
        bool fine = true;
        for (int i = 0; i < 10; ++i) {
            cin >> ball;
            if (max(Atop, Btop) < ball) {
                if (Atop >= Btop) Atop = ball;
                else Btop = ball;
            } else if (Atop < ball) {
                Atop = ball;
            } else if (Btop < ball) {
                Btop = ball;
            } else {
                fine = false;
            }
        }
        cout << (const char *)(fine ? "YES" : "NO") << endl;
    }
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

		if (d[j] < va[ca - 1] || d[j] < vb[cb - 1]) {
			cout << "NO" << endl;
			goto FINLOOP;
		}

			else if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb - 1]) {
				vb[cb] = d[j];
				cb++;
			}
			
		}
		cout << "YES" << endl;

		FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int arr[10],used[10];
void DFS(int pre,int cur)
{
   if(cur<10&&arr[pre]<arr[cur])
   {
	   used[cur]=1;
	   DFS(cur,cur+1);
   }
   else if(cur<10&&arr[pre]>=arr[cur])
	   DFS(pre,cur+1);
}
int main()
{
   int T,pre;
   bool judge;
   cin>>T;
   while(T--)
   {
     for(int i=0;i<10;i++)
		 cin>>arr[i];
	 for(int i=0;i<10;i++)
	 {
		 memset(used,0,sizeof(used));
		 used[i]=1;
	     DFS(i,i+1);
		 judge=false;
		 pre=0;
	     for(int j=0;j<10;j++)
		    if(used[j]==0)
				if(pre>=arr[j])
			{
				judge=true;
				break;
			}else pre=arr[j];
		 if(!judge)
		 {
			 cout<<"YES"<<endl;
			 break;
		 }
	 }
	 if(judge)cout<<"NO"<<endl;
   }

}

C++: #include<iostream>
#include<stack>
using namespace std;
int a[15];
stack <int> l,r;
bool flag;
void dfs(int x)
{
	if(x>10)
	{
		flag=true;
		return;
	}
	if(flag)
	  return;
	if(a[x]>l.top())
	{
		l.push(a[x]);
		dfs(x+1);
		l.pop();
	}
	if(a[x]>r.top())
	{
		r.push(a[x]);
		dfs(x+1);
		r.pop();
	}
}
int main ()
{
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		l.push(0);r.push(0);
		for(int i=1;i<=10;i++)
		  cin>>a[i];
		dfs(1);
		if(flag==true)
		  cout<<"YES"<<endl;
		else
		  cout<<"NO"<<endl;
		flag=false;
		while(!l.empty())
		  l.pop();
		while(!r.empty())
		  r.pop();
	}
	return 0;
}

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

#define SIZE 10

int ary[SIZE];

string solve(int a, int b, int f) {
	if (f >= 10) return "YES";
	
	if (ary[f] > a) return solve(ary[f], b, f + 1);
	if (ary[f] > b) return solve(a, ary[f], f + 1);

	return "NO";
}

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

	for (int i = 0; i++ < n;) {
		for (int j = 0; j < SIZE; j++) {
			cin >> ary[j];
		}
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

C++: #include <cstdio>
int ball[10];
bool dfs(int n,int b,int c) {
	if(n==10) {
		return true;
	}
	bool res=false;
	if(b<ball[n]) {
		res|=dfs(n+1,ball[n],c);
	}
	if(c<ball[n]) {
		res|=dfs(n+1,b,ball[n]);
	}
	return res;
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++) {
			scanf("%d",&ball[j]);
		}
		printf("%s\n",dfs(0,0,0)?"YES":"NO");
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;

  cin >> n;
  while (n != 0){
    stack<int> a, b;
    int s[10];
    bool judge = true, j = false;
    for (int i = 0; i < 10; i++){
      cin >> s[i];
    }
    a.push(s[0]);
    for (int i = 1; i < 10; i++){
      if (a.top() < s[i]){
        a.push(s[i]);
      }
      else if (!j){
        b.push(s[i]);
        j = true;
      }
      else if (b.top() < s[i]){
        b.push(s[i]);
      }
      else {
        judge = false;
        break;
      }
    }

    if (judge){
      cout << "YES\n";
    }
    else {
      cout << "NO\n";
    }
    n--;
  }
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±????????´????
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????????¬????????????\???????????????????????????????????¶???????´???§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10];


int main() {
  int T;
  cin >> T;
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: 
#include<stdio.h>

//探索再帰関数
bool tansaku(int count,int ans[],int a_max,int b_max,bool flg)
{
	//カウントが１０なら終了
	if (count == 10)
	{
		return true;
	}
	//trueじゃないなら探索を続ける
	if (flg == false)
	{
		//aの最大より新しいやつの方が大きいとき
		if (a_max < ans[count])
		{
			//aの上に格納
			a_max = ans[count];
			//答え配列のカウント変数をインクリメント
			count++;
			//再帰関数からの戻り値を格納
			bool hozon = tansaku(count,ans,a_max,b_max,flg);
			//trueを消さないように
			if (hozon == true)
			{
				flg = true;
			}
		}
		//bの最大より大きいとき
		if (b_max < ans[count])
		{
			//bに入力配列[count]を格納
			b_max = ans[count];
			count++;
			bool hozon = tansaku(count,ans,a_max,b_max,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
	}
	return flg;
}
int main(void)
{
	//回数を指定する変数
	int N = 0;
	//入力配列
	int a[10] = {0};
	//まとめて解答するflg
	bool ans_flg[100] = {false};
	scanf("%d",&N);
	for (int i = 0;i < N;i++)
	{
		//１０個のボールの入力
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		//count = 0、入力配列、a_max = 0,b_max = 0,flg = falseを送る
		if (tansaku(0,a,0,0,false) == true)
		{
			ans_flg[i] = true;
		}
	}
	//N回文の解答を出力
	for (int i = 0;i < N;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include <iostream>

int main(void)
{
	int n;
	std::cin >> n;
	for(int j=0; j<n; j++)
	{
		int top[2]={0,0};
		for(int i=0; ; i++)
		{
			//std::cout << top[0] << top[1] << std::endl;
			int next;
			std::cin >> next;
			if((top[0] < next)&&(top[1] < next))
			{
				if(top[0] < top[1])
					top[1]=next;
				else
					top[0]=next;
			}
			else if(top[0] < next)
				top[0]=next;
			else if(top[1] < next)
				top[1]=next;
			else
			{
				std::cout << "NO" << std::endl;
				for(int k=1; k+i < 10; k++)
					std::cin >>next;
				break;
			}

			if(i==9)
			{
				std::cout << "YES" << std::endl;
				break;
			}
		}
	}
	return 0;
}