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 <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;
int a[maxn];
int vis[maxn];

void dfs(int cur , int next)
{
    if(cur >= 10 || next >= 10) return ;
    else{
        if(a[cur] < a[next]){
             vis[next] = 1;
             dfs(next , next + 1);
        }
        else{
            dfs(cur , next + 1);
        }
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }
        int flag = 0;
        int y = 0;
        for(int i = 0 ; i < 10 ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1);
            int tp = -1;
            flag = 0;
            for(int j = 0 ; j < 10 ; j ++){
                if(vis[j] == 0){
                    if(a[j] > tp){
                        tp = a[j];
                    }
                    else{
                        flag = 1;
                        break;
                    }
                }
            }
            if(flag == 0)
            {
                
                y = 1;
                cout << "YES" << endl;
                break;
            }
        }
        if(y == 0) cout << "NO" << endl;
    }
}

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]);

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

      }

        for(int i=0;i<b.size();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 <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int b = 0, c = 0;
bool push(vector<int> ball) {
    vector<int>::iterator ite;
    for(ite = ball.begin(); ite != ball.end(); ite++) {
        if(*ite > b) b = *ite;
        else if (*ite > c) c = *ite;
        else return(false);
    }
    return(true);
}

int main(void) {
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            vec.push_back(input);
        }
        if(push(vec)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return(0);
}

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

stack<int> b,c;

int main()
{
    int ball,n;
    bool flag = true;
    scanf("%d", &n);
    for(int i=0;i<n;++i) {
        for(int j=0;j<10;++j) {
            scanf("%d", &ball);
            if (b.empty())      { b.push(ball); continue; }
            if (b.top() < ball) { b.push(ball); continue; }
            if (c.empty())      { c.push(ball); continue; }
            if (c.top() < ball) { c.push(ball); continue; }
            flag=false;
            break;
        }
        (flag) ? puts("YES") : puts("NO");
    }

    return 0;
}

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

int main() {
    int T; cin >> T;
    while (T--) {
        int a = 0, b = 0, succ = 1;
        for (int i = 0; i < 10; i++) {
            int n; scanf("%d", &n);
            if (a > b) {
                if (n > a) a = n;
                else if (n > b) b = n;
                else succ = 0;
            } else {
                if (n > b) b = n;
                else if (n > a) a = n;
                else succ = 0;
            }
        }
        puts(succ ? "YES" : "NO");
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

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;
}

C++: #include<iostream>

using namespace std;

int main(){

	int n;
	cin >> n;
	bool test = false;
	
	while( n-- ) {
		
		int A[10] = {0};
		int B[10] = {0};
	
		int j = 0, k = 0;
		int a;
		
		for(int i=0;i<10;i++) {
			
			cin >> a;
			
			if( a > A[j] ) {
				
				A[j] = a;
				A[j+1] = a;
				j++;
				
			}
			else {
				if( a > B[k]) {
					
					B[k] = a;
					B[k+1] = a;
					k++;
					
				}
			}
		}
		if ( j + k == 10)
			cout << "YES\n";
		else
			cout << "NO\n"; 
		
	}
	
    return 0;
}