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

#include <cstdio>

int a[10];

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

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

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

using namespace std;



void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf_s("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

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

bool isSortable(int min_b, int min_c, int *l)
{
    int first;
    bool res1, res2;

    first  = l[0];
    if (first == 0) return true;
    l++;
    // case1 firstをBに入れた場合
    if(first < min_b) {  // firstがmin_bより小さいときはfalse
        res1 = false;
    } else {             // firstはmin_bより大きい
        res1 = isSortable(first, min_c, l);
    }
    // case2 firstをCに入れた場合
    if(first < min_c) {
        res2 = false;
    } else {
        res2 = isSortable(min_b, first, l);
    }

    return (res1 || res2);
}

int main(void)
{
    int n, i, a[11];

    cin >> n;

    for(; n > 0 ; n--) {
        for(i = 0 ; i < 10 ; i++) {
            cin >> a[i];
        }
        a[10] = 0;
        if (isSortable(0, 0, a)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int I = 0; I < N; I++) {
    int b = 0, c = 0;
    for (int i = 0; i < 10; i++) {
      int x;
      cin >> x;
      if (x < b)
        if (x < c) {
          cout << "NO" << endl;
          goto next;
        } else
          c = x;
      else
        b = x;
    }
    cout << "YES" << endl;
next:;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num; cin >> num;
    int ans = 0;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            bool result = push(input);
            if(!result) ans += INT_MIN;
            else ans++;
        }
        if(ans >= 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int const MAXN=1e2+9;
int n;
int t1=1;
int t2=1;
int a[MAXN]={0};
int s1[MAXN]={0};
int s2[MAXN]={0};
bool used[MAXN]={false};

bool check(int *s,int t)
{
	for(int i=1;i<t-1;i++)
		if(!(s[i]<s[i+1]))
			return false;
	return true;
}

bool dfs(int i)
{
	if(i==n)
	{
		t2=1;
		for(int i=1;i<=n;i++)
			if(!used[i])
				s2[t2++]=a[i];
		if(check(s1,t1)&&check(s2,t2))
			return true;
		return false;
	}
	if(dfs(i+1))
		return true;
	if(a[i]>=s1[t1-1])
	{
		used[i]=true;
		s1[t1++]=a[i];
		if(dfs(i+1))
			return true;
		used[i]=false;
		t1--;
	}
	return false;
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		n=10;
		t1=1;
		t2=1;
		memset(a,0,sizeof(a));
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		memset(used,false,sizeof(used));
		for(int i=1;i<=n;i++)
			cin>>a[i];
		s1[t1++]=a[1];
		used[1]=true;
		if(dfs(2))
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
	return 0;
}

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

int a[10],b[10],c[10];

void initial()
{
	for(int i=0;i<10;i++)
	{
	 b[i]=-1;
         c[i]=-1;
	}
}
bool judge()
{
  int p=0,q=0,i;
  initial();
  b[0]=a[0];
  for(i=1;i<10;i++)
  {
	  if(a[i]>b[p])b[++p]=a[i];
	  else if(q==0)c[q++]=a[i];
	  else if(a[i]>c[q-1])c[q++]=a[i];
	  else 
	  {
		  return false;
		  break;
	  }
  }
  if(i==10)
    return true;
}

int main()
{
	int num;
	cin>>num;
	while(num--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(judge()?"YES":"NO");
	}
return 0;
}

C++: import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();//the number of test case
		for(int i=0;i<n;i++){
			int[] d=new int[10];
			for(int j=0;j<10;j++){
				d[j]=sc.nextInt();
			}
			int a=-999999;int b=-999999;
			//??????a<=b????????????????????????
			outside:for(int j=0;j<10;j++){
				if(d[j]>b)b=d[j];
				else if(d[j]>a)a=d[j];
				else{
					System.out.println("NO");
					break outside;
				}
				if(a>b){
					int dummy=b;
					b=a;
					a=dummy;
				}
				if(j==9)System.out.println("YES");
			}
		}
	}
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	for( int i = 0; i < n; ++i ) {
		vector<int> a( 10 );
		for( auto& v: a ) { cin >> v; }

		bool result = true;
		int x = 0;
		int y = 0;

		for( int j = 0; j < 10; ++j ) {
			if( a[j] > x ) {
				x = a[j];
			}
			else if( a[j] > y ) {
				y = a[j];
			}
			else {
				result = false;
				break;
			}
		}

		cout << (result ? "YES" : "NO") << '\n';
	}
}

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

using namespace std;


int q;
int Ball[10];
bool flag;
vector<string> log_vec;

bool is_satisfies(vector<int> a) {
    vector<int> copy = a;
    sort(a.begin(), a.end());
    return a == copy;
}

void bfs(int i, vector<int> B, vector<int> C) {
    if (i == 9) {
        if (is_satisfies(B) && is_satisfies(C))
            flag = true;
        else
            flag = flag == true ? true : false;
    } else {
        vector<int> temp;

        temp = B;
        temp.push_back(Ball[i]);
        bfs(i + 1, temp, C);

        temp = C;
        temp.push_back(Ball[i]);
        bfs(i + 1, B, temp);
    }
}

void solve() {
    vector<int> B, C;
    flag = false;

    bfs(0, B, C);

    if (flag)
        log_vec.push_back("YES");
    else
        log_vec.push_back("NO");
}

int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 10; ++j)
            scanf("%d", &Ball[j]);

        solve();
    }

    for (int i = 0; i < log_vec.size(); ++i) {
        cout << log_vec[i] << endl;
    }
}