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>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;

	while(cin >> n){
		vector<int> ball;
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back() && b < ball.back()){
				if(a > b){
					a = ball.back();
				}else{
					b = ball.back();
				}
			}else if(a < ball.back()){
				a = ball.back();
			}else if(b < ball.back()){
				b = ball.back();
			}else{
				check = false;
			}
			ball.pop_back();
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<cstdio>
#include<vector>
using namespace std;
int main(){
    int n,a[10];
    scanf("%d",&n);
    for(int ix=0;ix<n;ix++){
        for(int jx=0;jx<10;jx++){
            scanf("%d",&a[jx]);
        }
        bool is=false;
        for(int i=0;i<(1<<10);i++){
            vector<int> b,c;
            for(int j=0;j<10;j++){
                if(i&(1<<j))b.push_back(a[j]);
                else c.push_back(a[j]);
            }
            bool isb=true,isc=true;
            if(!b.empty()){
                for(int j=1;j<b.size();j++){
                    if(b[j-1]>b[j]){
                        isb=false;
                        break;
                    }
                }
            }
            if(!c.empty()){
                for(int j=1;j<c.size();j++){
                    if(c[j-1]>c[j]){
                        isb=false;
                        break;
                    }
                }
            }
            if(isb&&isc){
                is=true;
                break;
            }
        }
        if(is)printf("YES\n");
        else printf("NO\n");
    }
}

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

signed main()
{
  int n;
  vector<int> kanade;
  cin >> n;

  for (int i = 0; i < n; i++) {
    kanade.clear();
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      kanade.push_back(tmp);
    }

    int b = 0, c = 0;
    bool hayami = true;
    for (int j = 0; j < 10; j++) {
      if (b == 0 || b < kanade[j]) {
        b = kanade[j];
      } else if (c == 0 || c < kanade[j]) {
        c = kanade[j];
      } else {
        hayami = false;
      }
    }

    if (hayami) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return (0);
}

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

const int N = 10;

int a[N];

void input()
{
    for (int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
    }
}

void solve()
{
    bool res = false;
    for (int k = 0; k < (1<<10); k++) {
        int num = 0;
        int i;
        for (i = 0; i < N; i ++) {
            if ( (1 << i)&k ) {
                if (a[i] > num)
                    num = a[i];
                else
                    break;
            }
        }
        if (i < N)
            continue;
        num = 0;
        for (i = 0; i < N; i ++) {
            if ( ((1 << i)&k) == 0 ) {
                if (a[i] > num)
                    num = a[i];
                else
                    break;
            }
        }
        if (i == N) {
            res = true;
            //printf("k=%d\n", k);
            break;
        }
    }
    if (res)
        printf("YES\n");
    else
        printf("NO\n");
}

int main(void)
{
    int t;
    cin >> t;
    while (t--) {
        input();

        solve();
    }

    return 0;
}

C++: #include <stdio.h>
#define Max_N 10

int N;
int preA,preB;
int data[Max_N+1];

bool dfs(int x){
	if(x==10) return true;
	if(preA<data[x]){
		preA=data[x];
		if(dfs(x+1)) return true;
	}
	if(preB<data[x]){
		preB=data[x];
		if(dfs(x+1)) return true;
	}
	return false;
}

void solve(){
	preA=0;preB=0;
	if(dfs(0)) printf("YES\n");
	else printf("NO\n"); 
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&data[j]);
		}
		solve();
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int N;

int nums[10];

bool dfs(int a, int b, int i) {
	if (i == 10) {
		return true;
	}
	bool ret = false;
	if (nums[i] > a) {
		ret = ret || dfs(nums[i], b, i + 1);
	}
	if (nums[i] > b) {
		ret = ret || dfs(a, nums[i], i + 1);
	}
	return ret;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int i = 0; i < 10; i++) {
			cin >> nums[i];
		}
		
		if (dfs(-1, -1, 0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
        if(flagb) return true;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
        if(flagc) return true;
    }
    return false;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

C++: #include<iostream>
main(){
int n,i,A,B,C;
for(std::cin>>n;n-->0;puts(i>20?"NO":"YES"))
 for(B=C=i=0;i++<10;){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:i=30;
 }
}

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

using namespace std;



int main(){
	int n;
	int left[11],right[11];
	int l=1,r=1;
	int number;
	bool T = 1;

	memset(left,0,sizeof(left));
	memset(right,0,sizeof(right));

	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> number;
			if(left[l-1] < number && (number < right[r-1] || (left[l-1] > right[r-1] && right[r-1] < number))){
				left[l] = number;
				l++;
			}else if(right[r-1] < number){
				right[r] = number;
				r++;
			}else if(left[l-1] == right[r-1]){
				left[l] = number;
				l++;
			}else {
				cout << "NO" << endl;
				T = 0;
				break;
			}
		}

		if(T){
			cout << "YES" << endl;
			T = 1;
		}
	}
}