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 <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    stack<int> bs, cs;
    bool flag = true;
    bs.push(0);
    cs.push(0);
    REP(j, 10) {
      int a = nextInt();
      if (bs.top() < a) {
        bs.push(a);
      } else if (cs.top() < a) {
          cs.push(a);
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include<cstdio>
#include<algorithm>
#define MAXL 10
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t,last1=0,last2=0;	//假?last1>last2
		bool flag=0;
		for(int j=1;j<=10;j++){
			scanf("%d",&t);
			if(last1<t)	last1=t;
			else
				if(last2<t)	last2=t;
				else flag=1;
			if(last1<last2)	swap(last1,last2);
		}
		if(flag==0)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;

	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int b[10];
  
bool dfs(int i,int j,int k){
  if(k==10)
    return true;
  if(i<b[k]){
    if(dfs(b[k],j,k+1))return true; 
  }
  if(j<b[k]){
    if(dfs(i,b[k],k+1))return true;
  }
  return false;
}
 
int main(){
  int a;
  cin >> a;
  while(a>0){
    for(int i=0;i<10;i++){
      cin >> b[i];
    }
    int p=dfs(0,0,0);
    if(p!=0)
      cout << "YES" << endl;
    else
      cout << "NO" <<endl;
    a--;
  }
  return 0;
}

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

int ball[10];

bool dfs(int b, int c, int k){
	if (k >= 10) return true;
	if (b > ball[k] && c > ball[k]) return false;
	if (b < ball[k] && c > ball[k]) return dfs(ball[k], c, k+1);
	if (b > ball[k] && c < ball[k]) return dfs(b, ball[k], k+1);
	return dfs(ball[k], c, k+1) || dfs(b, ball[k], k+1);
}

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	REP(j, 10){
    		cin >> ball[j];
    	}
    	if (dfs(0, 0, 0)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}

C++: #include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
bool flag;
int ball[15];
bool dfs(int x, int l, int r){
    if(ball[x] > l){
        if(x == 9) return true;
        if(dfs(x+1, ball[x], r)) return true;
    }
    if(ball[x] > r){
        if(x == 9) return true;
        if(dfs(x+1, l, ball[x])) return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--){
        for(int i = 0; i < 10; ++i) cin >> ball[i];
        bool flag = dfs(0, 0, 0);
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
const int NUM=15;
int num[NUM];
bool vis[NUM];
void dfs(int i);
int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
        int ans=0;
        memset(vis,0,sizeof vis);
        for (int i=0; i<10; i++)
            scanf("%d",&num[i]);
        /*for (int i=0; i<10; i++)
        {
            if (!vis[i])
            {
                vis[i]=1;
                ans++;
                dfs(i);
            }
        }
        if (ans==1||ans==2)
            printf("YES\n");
        else
            printf("NO\n");*/
        int l=0,r=0,flag=1;
        for(int j=0; j<10; j++)
        {
            if(l<num[j])l=num[j];
            else if(r<num[j])r=num[j];
            else flag=0;
            if(flag==0)break;
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
/*void dfs(int i)
{
    for (int j=i+1; j<10; j++)
    {
        if (!vis[j]&&num[j]>=num[i])
        {
            vis[j]=1;
            dfs(j);
        }
    }
}*/

C++: #include<iostream>

using namespace std;
int balls[11];
bool res;
int n;

bool dfs(int left, int right,int i){
        if(i==9) return balls[left]<balls[i] || balls[right] < balls[i];
        if(balls[i] > balls[left]) return dfs(i, right, i+1);
        else if(balls[i] > balls[right]) return dfs(left, i, i+1);
        else return false;
}

void solve(){
        for (int i = 0; i < 10; ++i) {
                cin >> balls[i];

        }
        balls[10] = -1;
        res = dfs(10,10,1);
        if(res){
                cout << "YES" << endl;
        }else{
                cout << "NO" << endl;
        }
}

int main(){
        ios_base::sync_with_stdio(false);
        cin >> n;
        for (int i = 0; i < n; ++i) {
                solve();
        }
        return 0;
}