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 ball[10];
int b,c;

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        if(dfs(m+1,ball[m],right)) return true;
    }
    if(ball[m]>right){
        if(dfs(m+1,left,ball[m])) return true;
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

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

using namespace std;

int nums[10];

bool check_recursion(int i, int left, int right){
	if(i == 10) return true;
	if(nums[i] > left) check_recursion(i+1, nums[i], right);
	if(nums[i] > right) check_recursion(i+1, left, nums[i]);
	
	return false;
}

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

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);

	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;
			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				
				//if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				//}
				//どっちにも入る場合
				/*
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}*/
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int a=0, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a>x[i]) {
				if(b<x[i])
					b=x[i];
			}
			else {
				if(b>x[i])
					a=x[i];
				else
					a>b ? a : b =x[i];
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

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

int B, C, num[20], b, c;

string dfs(int x){
  if(x == 10) return "YES";
  else if(B>num[x]){
    if(C<num[x]){
      C = num[x];
      return dfs(x+1);
    }
    else return "NO";
  }
  else{
    B = num[x];
    return dfs(x+1);
  }
}

int main(void){
  int N;
  while(cin >> N){
  B = 0;
  C = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  string str = dfs(0);
  cout << str << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void)
{
	int n;

	cin >> n;
	while (n-- != 0)
	{
		int A[10] = {}, B[10] = {}, C[10] = {}, countb = 0, countc = 0;
		bool f = true;
		for (int i = 0; i < 10; i++)
		{
			cin >> A[i];
		}
		B[countb++] = A[0];
		for (int i = 1; i < 10; i++)
		{
			if (B[countb - 1] < A[i]) B[countb++] = A[i];
			else if (countc == 0) C[countc++] = A[i];
			else if (B[countb - 1] > A[i] && C[countc - 1] < A[i]) C[countc++] = A[i];
			else f = false;
		}
		//for (int i = 0; i < sizeof(B) / sizeof(*B); i++) cout << "B" << i << " =" <<B[i] << endl;
		//for (int i = 0; i < sizeof(C) / sizeof(*C); i++) cout << "C" << i << "=" << C[i] << endl;
		if (f == true) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
int x[10];
int dp[11][11][11];

string solve(){
  fill_n((int*)dp, 11 * 11 * 11, 0);
  dp[0][0][0] = 1;
  for(int i = 1; i <= 10; ++i){
    int v = x[i - 1];
    rep(j, 11){
      rep(k, v){
        dp[i][j][v] += dp[i - 1][j][k];
      }
    }
    rep(k, 11){
      rep(j, v){
        dp[i][v][k] += dp[i - 1][j][k];
      }
    }
  }
  rep(j, 11){
    rep(k, 11){
      if(dp[10][j][k]){
        return "YES";
      }
    }
  }
  return "NO";
}

int main(){
  cin >> n;
  rep(i, n){
    rep(j, 10){
      cin >> x[j];
    }
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			tube2[i] = 0;
		}
		
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

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

using namespace std;

int a[10];

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

    while(t--)
    {
        for(int i = 0; i < 10; ++i)
        {
            cin>>a[i];
        }

        vector<int> x[2];
        auto lar = &x[0];
        auto sma = &x[1];

        bool ans = true;

        for(int i = 0; i < 10; ++i)
        {
            int c = a[i];

            if(i == 0){
                lar->push_back(c);
            }
            else if(c >= lar->back())
            {
                lar->push_back(c);
            }
            else if(sma->empty())
            {
                sma->push_back(c);
                
            }
            else if(c >= sma->back())
            {
                sma->push_back(c);
                
            }
            else
            {
                ans = false;
                break;
            }
            
        }
        if(ans)
            cout<<"YES" <<endl;
        else
            cout<<"NO" <<endl;

    }
}

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

using namespace std;

int n;
vector<int> vec;
int lcount, rcount, l, r;

bool dfs(int i)
{
	if(i == 10) return true;
	if(lcount < 10 && l < vec[i]){ l = vec[i]; if(dfs(i + 1)) return true; }
	if(rcount < 10 && r < vec[i]){ r= vec[i]; if(dfs(i + 1)) return true; }
	return false;
}

int main()
{
	cin >> n;
	for (int j = 0; j < n; j++)
	{
		lcount = 0; rcount = 0; l = 0; r = 0;
		vec.resize(10);

		for (int i = 0; i < 10; i++)
		{
			cin >> vec[i];
		}	
		cout << (dfs(0) ? "YES" : "NO") << endl;
	}
	return 0;
}

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