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 <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int n[10];
int h, w;
int b,c;

bool dfs(int cnt) {
  if(cnt == 10) return true;
  if(n[cnt] > n[b]) {
    int tmp = b;
    b = cnt;
    if(dfs(cnt+1)) return true;
    b = tmp;
  }
  if(n[cnt] > n[c]) {
    int tmp = c;
    c = cnt;
    if(dfs(cnt+1)) return true;
    c = tmp;
  }
  return false;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

  int num;
  cin >> num;
  rep(i,0,num) {
    rep(j,0,10) cin >> n[j];
    b = 0;
    c = 1;

    if(dfs(2)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

	return 0;
}

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

int ball[10];
int b,c;

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        if(dfs(m+1,ball[m],right)) return true;
    }
    if(ball[m]>right){
        if(dfs(m+1,left,ball[m])) return true;
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

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

using namespace std;

int nums[10];

bool check_recursion(int i, int left, int right){
	if(i == 10) return true;
	if(nums[i] > left) check_recursion(i+1, nums[i], right);
	if(nums[i] > right) check_recursion(i+1, left, nums[i]);
	
	return false;
}

int main(){
	int n;
	bool ans;
	cin>>n;

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);

	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;
			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				
				//if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				//}
				//どっちにも入る場合
				/*
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}*/
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int a=0, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a>x[i]) {
				if(b<x[i])
					b=x[i];
			}
			else {
				if(b>x[i])
					a=x[i];
				else
					a>b ? a : b =x[i];
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

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

int B, C, num[20], b, c;

string dfs(int x){
  if(x == 10) return "YES";
  else if(B>num[x]){
    if(C<num[x]){
      C = num[x];
      return dfs(x+1);
    }
    else return "NO";
  }
  else{
    B = num[x];
    return dfs(x+1);
  }
}

int main(void){
  int N;
  while(cin >> N){
  B = 0;
  C = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  string str = dfs(0);
  cout << str << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void)
{
	int n;

	cin >> n;
	while (n-- != 0)
	{
		int A[10] = {}, B[10] = {}, C[10] = {}, countb = 0, countc = 0;
		bool f = true;
		for (int i = 0; i < 10; i++)
		{
			cin >> A[i];
		}
		B[countb++] = A[0];
		for (int i = 1; i < 10; i++)
		{
			if (B[countb - 1] < A[i]) B[countb++] = A[i];
			else if (countc == 0) C[countc++] = A[i];
			else if (B[countb - 1] > A[i] && C[countc - 1] < A[i]) C[countc++] = A[i];
			else f = false;
		}
		//for (int i = 0; i < sizeof(B) / sizeof(*B); i++) cout << "B" << i << " =" <<B[i] << endl;
		//for (int i = 0; i < sizeof(C) / sizeof(*C); i++) cout << "C" << i << "=" << C[i] << endl;
		if (f == true) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
int x[10];
int dp[11][11][11];

string solve(){
  fill_n((int*)dp, 11 * 11 * 11, 0);
  dp[0][0][0] = 1;
  for(int i = 1; i <= 10; ++i){
    int v = x[i - 1];
    rep(j, 11){
      rep(k, v){
        dp[i][j][v] += dp[i - 1][j][k];
      }
    }
    rep(k, 11){
      rep(j, v){
        dp[i][v][k] += dp[i - 1][j][k];
      }
    }
  }
  rep(j, 11){
    rep(k, 11){
      if(dp[10][j][k]){
        return "YES";
      }
    }
  }
  return "NO";
}

int main(){
  cin >> n;
  rep(i, n){
    rep(j, 10){
      cin >> x[j];
    }
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			tube2[i] = 0;
		}
		
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}