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 B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
		int i=0;
        cin>>N;

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

            if(DFS(A)==true)
                cout<<"YES"<<endl;
            else
				cout<<"NO"<<endl;

			
??????????????????i++;
        }
                
	
        return 0;
}

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

using namespace std;

int N;
int l[15];
int b,c;
//int res[1000000000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
  //    res[k]=0;
      printf("NO");
      return;
    }
  }
  printf("YES");
  return;
}


int main(){
  scanf("%d",&N);

  for(int i=0;i<N;i++){
    b,c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  /*for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }
*/

  return 0;
}

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

int a[10];

bool dfs(int n,int l,int r)
{
	if(n>=10)return true;
	if(l<a[n])if(dfs(n+1,a[n],r))return true;
	if(r<a[n])if(dfs(n+1,l,a[n]))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,-1,-1))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;


bool saiki(vector<int> ball,stack<int> B,stack<int> C){

    if(ball.size() == 0) return true;
    int temp = ball.front();
    bool flag1=false,flag2=false;
    ball.erase(ball.begin());
    if(temp > B.top()){
	B.push(temp);
       	flag1 = saiki(ball,B,C);
	B.pop();
    }
    if(temp > C.top()){
	C.push(temp);
	flag2 = saiki(ball,B,C);
    }
    return flag1 || flag2;
}


int main(){

    int N,temp;
    vector<int> ball;
    stack<int>B,C;
    B.push(0);
    C.push(0);
    cin >> N;
    for(int i=0;i<N;i++){
	for(int j=0;j<10;j++){
	    cin >> temp;
	    ball.push_back(temp);
	}
	if(saiki(ball,B,C)) cout << "YES" << endl;
	else cout << "NO" << endl;
	ball.clear();
    }
    return 0;
}

C++: #include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int i;
  for(i=0;i<n;i++){
    int a, b;
    a=b=0;
    int j;
    int t;
    for(j=0;j<10;j++){
      scanf("%d", &t);
      if(t > a){
        if(t > b){
          if(a > b) a = t;
          else b = t;
        }else {
          a = t;
        }
      }else if(t > b){
        b = t;
      }else {
        printf("NO\n");
        j=11;
      }
    }
    if(j!=12) puts("YES");
  }
}

C++: // 1.?取?入
// 2.把桶?来?去放球
// 3.?出?果
#include <stdio.h>
#include <string.h>
#define MAXN 15
int ball[MAXN];//A里的球?号
int bucket[2][MAXN];//?个桶
int num[2];//?个桶内当前球的数量
void init() {
    num[0]=num[1]=0;
    memset(ball,0,sizeof(ball));
    memset(bucket,0,sizeof(bucket));
}
void getInput() {
    for(int i=0;i<10;i++) scanf("%d",&ball[i]);
}

int dfs(int no,int bktno) {
    int state=0;
    // printf("%d\n",no);
    if(no>9) return 1;
    int bktno2=(bktno+1)%2;
    if(num[bktno]==0 || ball[no]>bucket[bktno][num[bktno]]) {
        bucket[bktno][++num[bktno]]=ball[no];
        state=dfs(no+1,bktno);
    } else if(num[bktno2]==0 || ball[no]>bucket[bktno2][num[bktno2]]) {
        bucket[bktno2][++num[bktno2]]=ball[no];
        state=dfs(no+1,bktno2);
    } else {
        num[bktno]--;
        if(num[bktno]==0) return 0;
        state=dfs(no-1,bktno2);
    }
    return state;
}

int main() {
#ifdef debug
    freopen("in.txt","r",stdin);
#endif
    int item;
    scanf("%d",&item);
    while(item--) {
        init();
        getInput();
        // for(int i=0;i<10;i++) {
        //     printf("%d ",ball[i]);
        // }
        // printf("\n");
        if(dfs(0,0)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}


//
//vector<int> L_bucket;
//vector<int> R_bucket;
//
//bool dfs2(int d){
//    if(d == 10) return true;
//    bool flag = false;
//    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
//        L_bucket.push_back(a[d]);
//        flag = dfs2(d+1);
//        L_bucket.pop_back();
//    }
//    if(flag) return true;
//    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
//        R_bucket.push_back((a[d]));
//        flag = dfs2(d+1);
//        R_bucket.pop_back();
//    }
//    if(flag) return true;
//    return false;
//}
//
//void solve2()
//{
//    if(dfs2(0)) printf("YES\n");
//    else printf("NO\n");
//}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

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

using namespace std;

int a[15];

bool solve(int n, int A, int B) {
	if (n == 10) return true;
	if (A < a[n] && solve(n+1, a[n], B)) return true;
	if (B < a[n] && solve(n+1, A, a[n])) return true;
	return false; 
}

int main() {
	int N;
	scanf("%d", &N);
	while (N--) {
		int i;
		for (i = 0; i < 10; i++) {
			scanf("%d", &a[i]);
		}
		if (solve(0, -1, -1)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int N;
int data[1000][10];
bool ans;

bool solve(int num) {
  stack<int> b, c;
  b.push(data[num][0]);
  for (int i = 1; i < 10; i++) {
    if (c.empty()) {
      int bt = b.top();
      (data[num][i] > bt ? b : c).push(data[num][i]);
    }
    else {
      int bt = b.top(), ct = c.top();
      if (data[num][i] > bt && data[num][i] > ct) (bt > ct ? b : c).push(data[num][i]);
      else if (data[num][i] > bt) b.push(data[num][i]);
      else if (data[num][i] > ct) c.push(data[num][i]);
      else return false;
    }
  }
  return true;
}

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

  for (int i = 0; i < N; i++) {
    ans = solve(i);
    cout << (ans ? "YES" : "NO") << endl;
  }


  return 0;
}