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<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;
      return;
    }
  }
  res[k]=1;
  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<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std;

const int maxn = 1000;
const int INF = 1e9+10;

int a[maxn];

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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        for(int i = 0; i < 10; i++) scanf("%d",&a[i]);
        if(dfs(0,0,0)) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin>>n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a){
					s1.push(a);
					continue;
					}
			}
			if (s2.top() < a){
					s2.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>  
#include<cstdio>  
#include<cstring> 
#include <cmath> 
#include<stack>
#include<vector>
#include<map> 
#include<set>
#include<queue> 
#include<algorithm>  
using namespace std;

typedef long long LL;
const int INF = (1<<30)-1;
const int mod=1000000007;
const int maxn=105;

int a[maxn];
int b[maxn],c[maxn];
int cnt1,cnt2;

bool ok(int b[],int c[]){
	for(int i=1;i<cnt1;i++){
		if(b[i] < b[i-1]) return false;
	}
	
	for(int i=1;i<cnt2;i++){
		if(c[i] < c[i-1]) return false;
	}
	return true;
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<10;i++) scanf("%d",&a[i]);
		
		int flag=0;
		for(int i=0;i< 1<<10;i++){
			 cnt1=0;cnt2=0;
			memset(b,0,sizeof(b));
			memset(c,0,sizeof(c));
			for(int j=0;j<10;j++){
				if(i>>j & 1) b[++cnt1]=a[j];
				else c[++cnt2]=a[j];				
			}
			
			if(ok(b,c)){
					flag=1;
					break;			
				}	
		//	printf("cnt1=%d  cnt2=%d\n",cnt1,cnt2);
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int x[10];
int func(int n,int r,int l){
    if(n == 10)return 1;
    if(x[n]>r){
        if(func(n+1,x[n],l))return 1;
    }
    if(x[n]>l){
        if(func(n+1,l,x[n]))return 1;
    }
    return 0;
}
int main(){
	int k;
	cin>>k;
	while(k-->0){
		for(int i=0;i<10;i++)
			cin>>x[i];
		if(func(0,0,0))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			cin >> o[i];
		int sum = o[i], num = 0;
		for (int k = 0; k < 10;k++) {
			if (o[k] < sum){
				num++;
				sum = o[k];
			}
		}
		l.push_back(num >= 2);
	}
	for (bool b : l) {
		if (b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n;
  int b[10]={0};
  int c[10]={0};
  int bcount=0,ccount=0,h=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<10;j++){
      cin >> n;
      if(b[0]==0) b[bcount] = n;
      else if(b[bcount]>c[ccount]&&b[bcount]<n){
    bcount++;
    b[bcount] = n;
      }
      else if(c[ccount]>b[bcount]&&c[ccount]<n){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n;
      }
      else if(b[bcount]>c[ccount]&&b[bcount]>n&&c[ccount]<n){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n;
      }
      else if(c[ccount]>b[bcount]&&c[ccount]>n&&b[bcount]<n){
    bcount++;
    b[bcount] = n;
      }
      else if(b[bcount]>n&&c[ccount]>n){
    cout << "NO" << endl;
    h = 1;
    break;
      }
    }
    if(h==0) cout << "YES" << endl;
    for(int i=0;i<10;i++){
      b[i] = 0;
      c[i] = 0;
    }
      bcount = 0;
      ccount = 0;
      h = 0;
  }
  return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int i, j;
	int ball[10];
	int a, b;
	int n;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		for (j = 0; j < 10; j++){
			scanf("%d", &ball[i]);
		}
		
		for (j = 0; j < 10; j++){
			if (ball[i] < a && ball [i] < b){
				printf("NO\n");
				break;
			}
			if (a > b && a < ball[i]){
				a = ball[i];
			}
			else if (a < b && b < ball[i]){
				b = ball[i];
			}
			else if (a < ball[i]){
				a = ball[i];
			}
			else if (b < ball[i]){
				b = ball[i];
			}
		}
		if (j == 10){
			printf("YES\n");
		}
	}
	return (0);
}