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>

using namespace std;

int ball[11],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=1;i<11;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,1);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	while (n--) {
		int a(0), b(0), x;
		bool f(true);
		rep(i, 0, 10) {
			cin >> x;
			if (a < x)a = x;
			else if (b < x)b = x;
			else f = false;
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[11];
bool dfs(int i,int l,int r){
	if(i==10)return true;
	if(dfs(i+1,a[i],r)&&a[i]>l)return true;
	if(dfs(i+1,l,a[i])&&a[i]>r)return true;
	return false;
}
int main(){
	int T;
	cin>>T;
	while(T--){
	for(int i=0;i<10;i++)
		cin>>a[i];
	if(dfs(0,0,0))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
	return 0;
}

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;// , a = 0, b = 0;
bool f = 1;
stack<int> s1, s2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (j == 0){
				s1.push(k);
				//a = s1.top();
			}
			else if (j == 1){
				s2.push(k);
				//b = s2.top();
			}
			else{
				if (s1.top() < k || s2.top() < k){
					if (k - s1.top() > k - s2.top()){
						s2.push(k);
					}
					else{
						s1.push(k);
					}
					//a = s1.top();
					//b = s2.top();
				}
				else{
					f = 0;
				}
			}
			//cout << a << b << "\n";
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

C++: #include<stdio.h>
 
int unname(int *ball,int i,int b,int c)
{
    if(i==10) return 1;
    if(c<ball[i]){
        c=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    if(b<ball[i]){
        b=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    return 0;
}
 
int main()
{
    int ball[10];
    int result,i;
    int b=0,c=0;
    for(i=0;i<10;i++)
    {
        scanf("%d",&ball[i]);
    }
    c=ball[0];
    i=0;
    result=unname(ball,i,b,c);
    if(result==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

C++: /*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
#include <cstring>
using namespace std;

int a[15];
int mark[15];
int count;

void dfs(int x)
{
	mark[x] = 1;
	for(int i=x+1; i<=9-i; i++)
		if(a[x]<a[i])
		{
			return dfs(i);
		}
		else
		{
			count++;
			return ;
			
		}
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		count=0;
		bool flag=false;
		memset(mark, 0, sizeof(mark));
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		for(int i=0; i<10; i++)
		{
			if(mark[i]==0)
				dfs(i);
		}
		if(count<=2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				st2.push(num[i]);
				continue;
			}
			if( st1.top() > num[i] && st2.top() > num[i] ){
				cout << "NO" << endl;
				break;
			}else if( st1.top() > st2.top() ){
				st1.push(num[i]);
			}else{
				st2.push(num[i]);
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int a[10], dp[16][16];

bool can() {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    rep (i, 10) {
        rep (j, 11) if (dp[i][j]) {
            const int pre = i == 0 ? 0 : a[i-1];
            if (a[i] > j) dp[i+1][pre] = 1;
            if (a[i] > pre) dp[i+1][j] = 1;
        }
    }
    rep (i, 11) if (dp[10][i]) return true;
    return false;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        rep (i, 10) scanf("%d", a+i);
        puts(can() ? "YES" : "NO");
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, max_len;
int num[11], dp[11];

int main(){
    //freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    while(n--){
        for(int i=0; i<10; i++){
            scanf("%d", &num[i]);
        }
        memset(dp, 0, sizeof(dp));
        max_len = 1;
        dp[0] = 1;
        
        for(int i=1; i<10; i++){
            for(int j=0; j<i; j++){
                if(num[i] < num[j])
                    dp[i] = max(dp[i], dp[j] + 1);
            }
            max_len = max(max_len, dp[i]);
        }

        if(max_len > 2)
            printf("NO\n");
        else 
            printf("YES\n");
    }
    return 0;
}