Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

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

int main(){
  int N,t,B,C;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    B = C = 0;
    int j;
    for( j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t) break;
      else if(B < t && C < t){
	if(B < C) B = t;
	else B = t;
      }
      else if(B < t) B = t;
      else if(C < t) C = t;
      //      cout << B << " ";
    }
    if(j == 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <stdio.h>
int main(){
int n,a,b,temp;
bool f;
scanf("%d",&n);
for(int i=0;i<n;i++){
a=b=0;
f=true;
for(int j=0;j<10;j++){
scanf("%d",&temp);
if(temp>a)a=temp;
else if(temp>b)b=temp;
else f=false;
}
if(f)printf("YES\n");
else printf("NO\n");
}
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: // 2015/07/03 Tazoe

#include <iostream>
using namespace std;

int A[10];

bool DFS(int I, int B, int C)
{
	if(I==10)
		return true;

	if(A[I] > B && DFS(I+1, A[I], C))	// Bに入れて最後まで並べられれば
		return true;

	if(A[I] > C && DFS(I+1, B, A[I]))	// Cに入れて最後まで並べられれば
		return true;

	return false;
}

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

	for(int i=0; i<N; i++){
		for(int j=0; j<10; j++){
			cin >> A[j];
		}

		if(DFS(0, 0, 0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
#include<map>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int a[10],x=0,y=0;
    stack<pair<int,int> > log;
    for(int i=0; i<10; i++) cin >>a[i];
    for(int i=0; i<10; i++){
      if(x>a[i] && y<a[i]) y = a[i];
      else if(x<a[i] && y>a[i]) x = a[i];
      else if(x<a[i] && y<a[i]){
	log.push(make_pair(x,i));
	x = a[i];
      }
      else if(x>a[i] && y>a[i]){
	if(log.empty()){
	  cout <<"NO"<<endl;
	  break;
	}
	x = log.top().first;
	i = log.top().second;
	y = a[i];
	log.pop();
      }
      if(i == 9) cout <<"YES"<<endl;
    }
  }
  return 0;
}

C++: /*
 * AOJ 0033: Ball
 * 题意：序号为1-10的10个球，按一定排列顺序进入2个队列之一，最终每队入队球的序号都为增序的方案是否存在。
 * 类型：贪心
 * 算法：对于每个球，若大于队列顶端元素，则可以记录该情况并继续递归。每次优先加入左边，可保证左边的顶端元素大于右边。
 */

#include <iostream>

using namespace std;

int balls[10];

int main() {
  //每次就先看左边能不能放，能放就放入，否则再看右边，右边也不能放，则不存在方案
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 10; i++) cin >> balls[i];
    int l = 0, r = 0;
    bool flag = true;
    for (int i = 0; i < 10; i++) {
      if (balls[i] > l) {
        l = balls[i];
      } else if (balls[i] > r) {
        r = balls[i];
      } else {
        flag = false;
        break;
      }
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}



// int a[10];


// int main() {
//   int T;
//   scanf("%d", &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;
//       }
//     }
//     printf("%s\n", ans ? "YES" : "NO");
//   }
//   return 0;
// }

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  for(int i=0;i<n;i++){
    long long a,b[11]={},c[11]={},cntb=1,cntc=1;
    bool f=true;
    for(int j=0;j<10;j++){
      cin >> a;
      if(b[cntb-1]>=a and c[cntc-1]>=a){
        cout << "NO" << endl;
        f=false;
        break;
      }
      if(b[cntb-1]<a and c[cntc-1]>=a){
        b[cntb]=a;
        cntb++;
      }else if(b[cntb-1]>=a and c[cntc-1]<a){
        c[cntc]=a;
        cntc++;
      }else{
        if(b[cntb-1]>c[cntc-1]){
          b[cntb]=a;
          cntb++;
        }else{
          c[cntc]=a;
          cntc++;
        }
      }
    }
    if(f){
      cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int s[10], n, b = 0, c = 0;
    bool flag = true;

    cin >> n;
    rep(i, n) {
        rep(i, 10)
            cin >> s[i];
        rep(i, 10) {
            if (s[i] > b)
                b = s[i];
            else if (s[i] > c)
                c = s[i];
            else
                flag = false;
        }
        
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: a[10];
int dfs(int l,int r,int i){
if(i>9)return 1;if(a[i]>l&&dfs(a[i],r,i+1))return 1;
if(a[i]>r&&dfs(l,a[i],i+1))return 1;
return 0;
}
main(n){
scanf("%d",&n);
for(;n;n--)
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),dfs(0,0,0)?puts("YES"):puts("NO");
return 0;
}

C++: #include<cstdio>


int num[10];
int m;

int main() {
	scanf("%d\n", &m);
	bool flag = true;
	while(m--)
	{ 
	    int l = 0;
	    int r = 0;
		flag = true;
		for (int i = 0; i < 10; i++)
			scanf("%d", &num[i]);
		for (int i = 0; i < 10; i++)
		{
			if (num[i] > l)
				l = num[i];
			else if (num[i] > r)
				r = num[i];
			else
			{
				flag = false;
				break;
			}
		}
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}


	return 0;
}

C++: #include<iostream>
#include<memory.h>
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>

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		std::cin >> n;
		if (q[0]<n) q[0] = n;
		else if (q[1]<n) q[1] = n;
		else break;
	}

	return ((i==num)? true: false);
}

int main(){
	int i, n;

	std::cin >> n;
	for (i=0; i<n; i++)
		std::cout << (judge(10)? "YES": "NO") << "\n";

	return 0;
}

C++: #include<stdio.h>
int main(){
	int a;
    scanf("%d",&a);
    while(a--){
     int b,flag=1;
     int right=0,left=0;
     for(int i=0;i<10;i++){
     	scanf("%d",&b);
     	if(b>right){
		 right=b;continue;}
		if(b>left){
			left=b;continue;
		}
		if(flag)
     	printf("NO\n");
     	flag=0;
	 }
	 if(flag)
	 printf("YES\n");
	}
	return 0;
}