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 <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int array[10];

bool dfs(int b,int c,int idx) {
    // cout<<b<<","<<c<<","<<idx<<endl;
    if(idx == 10) return true;

    int tb = array[idx] - b;
    int tc = array[idx] - c;

    if(tb<0 && tc<0) return false;

    bool ret = false;

    if(tb > 0) ret |= dfs(array[idx],c,idx+1);
    if(tc > 0) ret |= dfs(b,array[idx],idx+1);

    return ret;
}

void solve() {
    rep(i,10) cin>>array[i];

    string ans = "NO";
    if(dfs(0,0,0)) ans = "YES";
    cout<<ans<<endl;
}

int main() {
    cin>>n;
    rep(i,n) solve();
    return 0;
}

C++: #include <iostream>

using namespace std;

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

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

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\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 <cstdio>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            continue;
        else
            printf("YES\n");
    }
    return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int kuru[10];
bool solve(int l,int r,int co,int now);
int main(){
  int n;
  while(n--){
    for(int i=0;i<10;i++){
      cin>>kuru[i];
    }
    if(solve(0,0,0,0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}
bool solve(int l,int r,int co,int now){
  if(co==10)return true;
  if(l<kuru[now]){
    if(solve(kuru[now],r,co+1,now+1))return true;
    else return false;
  }
  if(r<kuru[now]){
    if(solve(l,kuru[now],co+1,now+1))return true;
    else return false;
  }
  else if(r>kuru[now] && l>kuru[now])return false;
}

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>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
int l = 0, m = 0;
bool f = 1;
stack<int> sb, sc;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
				l = sb.top();
			}
			else if (c == 0){
				sc.push(k);
				if (sb.top() < k){
					sc.push(sb.top());
					sb.push(k);
				}
				c++;
				m = sc.top();
			}
			else{
				if (sb.top() < k){
					sb.push(k);
					b++;
				}
				else if (sc.top() < k){
					sc.push(k);
					c++;
				}
				else{
					f = 0;
				}
				l = sb.top();
				m = sc.top();
			}
			//cout << l << " " << m << "\n";
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		REP(i,b){
			sb.pop();
		}
		REP(i, c){
			sc.pop();
		}
		b = 0;
		c = 0;
	}
}

C++: #include <iostream>

using namespace std;

int data[10];

int scan() {
  int r = 0;
  for (int i = 0; i < 9; i++)
    if (data[i] > data[i + 1]) r++;
  return r;
}

int main()
{
  int n, limit;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> data[j];
    if (scan() > 2)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }

  return 0;
}