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 <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<int> a(10), b, c;

void solve(vector<int> a){
	b.push_back(a[0]);
	c.push_back(0);
	for(int i = 1; i < 10; i++){
		if(a[i] - b[b.size() - 1] > 0 && a[i] - c[c.size() - 1] > 0){
			if(a[i] - b[b.size() - 1] < a[i] - c[c.size() - 1]){
				b.push_back(a[i]);
			}else{
				c.push_back(a[i]);
			}
		}else if(a[i] - b[b.size() - 1] > 0 && a[i] - c[c.size() - 1] < 0){
			b.push_back(a[i]);
		}else if(a[i] - b[b.size() - 1] < 0 && a[i] - c[c.size() - 1] > 0){
			c.push_back(a[i]);
		}else{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> a[j];
		}
		solve(a);
	}
}

C++: #include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int a,b,n,i,j,x[10];
    scanf("%d",&n);
for(j=0;j<n;j++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
C.push(x[1]);
for(i=1;i<9;i++){
if(B.top()<x[i+1]){
B.push(x[i+1]);
}else if(C.top()<x[i+1]){
	C.push(x[i+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }

C++: #include <iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	while(N--){
		int pipe[2] = {0};
		int i=0;
		bool f=false;
		for(; i < 10; i++){
			int num;
			cin >> num;
			if(pipe[1] > pipe[0]){
				
				if(num > pipe[1]){
					pipe[1] = num;
				}else if(num > pipe[0]){
					pipe[0] = num;
				}else{
					f=true;
					break;
				}
				
			}else{
				if(num > pipe[0]){
					pipe[0] = num;
				}else if(num>pipe[1]){
					pipe[1] = num;
				}else{
					f=true;
					break;
				}
			}
			
		}
		if(!f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int t,n,i,j,mmax;
	int a[11];
	cin>>t;
	while(t--) {
		for(i=1;i<=10;i++) cin>>a[i];
		mmax=a[1];
		a[1]=-1;
		for(i=2;i<=10;i++) {
			if(a[i]>mmax) {
				mmax=a[i];
				a[i]=-1;
			}
		}
		mmax=-1;
		for(i=1;i<=10;i++) {
			if(a[i]==-1) continue;
			if(a[i]<mmax) break;
			mmax=a[i];
		}
		if(i==11) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n; cin>>n;
    while(n--){
        int amin = 0;
        int bmin = 0;
        int tmp;
        bool ans = true;
        for(int i=0;i<10;++i){
            cin>>tmp;
            if(tmp <= amin && tmp <= bmin){
                ans = false;
            }
            if(!ans) continue;
            if(tmp > amin && tmp > bmin){
                if(bmin > amin)
                    bmin = tmp;
                else
                    amin = tmp;
            }else if(tmp > amin)
                amin = tmp;
            else
                bmin = tmp;
        }
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
int n, arr[15];
bool flag;
void dfs(int x1, int x2, int y1, int y2, int cnt)
{
    if (x2 < x1 || y2 < y1)
        return;
    if (cnt == 10)
    {
        flag = true;
        return;
    }
    dfs(x2, arr[cnt], y1, y2, cnt + 1);
    dfs(x1, x2, y2, arr[cnt], cnt + 1);
}
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        for (int i = 0; i < 10; i++)
            scanf("%d", &arr[i]);
        flag = false;
        dfs(0, 0, 0, 0, 0);
        if (flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<bitset>
#include<queue>
#include<string>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,n,a) for(int i=n;i>a;i--)
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,INF,sizeof(x))
#define INF 100000000
using namespace std;
typedef pair<int,int> p;
typedef long long LL;
int aa[15];
int main()
{
    //freopen("input.in","r",stdin);
    int n;
    bitset<10> dis;
    while(cin>>n)
    {
        for(int i=1;i<=10;i++)
        cin>>aa[i];
        int all=1024;
        while(all>0)
        {
            dis=static_cast<bitset<10> >(all);
            bool flag=true;
            int left=0,right=0;
            for(int i=1;i<=10;i++)
            {
                if(dis[i-1])
                {
                    if(aa[i]>left)
                    {
                         left=aa[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
                else
                {
                    if(aa[i]>right)
                    {
                        right=aa[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
            }
            if(flag)
            {
                break;
            }
            else all--;
        }
        if(all>0)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				cin.ignore(64, "\n");
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

bool ballTest(int *balls, int *b, int numB, int *c, int numC, int num)
{
        if (num <= 0) {
                return true;
        }
        if (balls[0] > b[numB - 1]) {
                b[numB] = balls[0];
                if (ballTest(&balls[1], b, numB + 1, c, numC, num - 1)) {
                        return true;
                }
        }
        if (balls[0] > c[numC - 1]) {
                c[numC] = balls[0];
                if (ballTest(&balls[1], b, numB, c, numC + 1, num - 1)) {
                        return true;
                }
        }
        return false;
}


int main(int argc, char **argv)
{
        int num;

        cin >> num;

        for (int i = 0; i < num; i++) {
                int balls[11];
                int b[10], c[10];
                int numB, numC;

                b[0] = c[0] = 0;
                numB = numC = 1;
                cin >> balls[1] >> balls[2] >> balls[3] >> balls[4] >> balls[5] >> balls[6] >> balls[7] >> balls[8] >> balls[9] >> balls[10];
                if (ballTest(&balls[1], b, 1, c, 1, 10)) {
                        cout << "YES\n";
                } else {
                        cout << "NO\n";
                }
        }
        return 0;
}