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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
 
int main()
{	
	int n;
	cin>>n;
	while(n--){
		int a[10];
		for(int i=0;i<10;i++){
			cin>>a[i];
		}
		bool rt1=true,rt2=true;
		for(int i=0;i<8;i=i+2){
			if(a[i]>a[i+2]) rt1=false;		
		}
		
		for(int i=1;i<8;i=i+2){
			if(a[i]>a[i+2]) rt2=false;		
		}
		if(rt1==true && rt2==true) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 9)return true;
	if(left < ball[de]){
		left = ball[de];
		return dfs(de + 1);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

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

int main()
{
    int n ;
	int ball[11] , b[11] , c[11];
	cin >> n ;
	for(int j=0 ; j<n ; j++){
		int flag=0, cntb=1 , cntc=1;
		for(int i=1 ; i<=10 ;i++){
			cin >> ball[i] ;
		}

		b[0]=0;
		c[0]=0;

		for(int i=1 ; i<=10 ; i++){
			if(b[cntb-1] < ball[i]){
				b[cntb]=ball[i];
				cntb++;
			}else if(c[cntc-1] < ball[i]){
				c[cntc]=ball[i];
				cntc++;
			}else{
				flag++;
				break;
			}
		}
		if(flag==0){
			cout <<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int a[13],b[13],c[13],flag;
void dfs(int step,int bn,int cn)
{
    if(step==10){
        flag=1;
        return ;
    }
    if(flag) return ;
    if(a[step]>b[bn]){
    	b[bn]=a[step];
    	dfs(step+1,bn+1,cn);
	}
    if(a[step]>c[cn]){
    	c[cn]=a[step];
    	dfs(step+1,bn,cn+1);
	}
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        flag=0;
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        dfs(0,0,0);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
const int N = 20 + 5;

int T;

int main()
{
    scanf("%d", &T);
    while(T--)
    {
        int left = 0, right = 0, flag = 0;
        for(int i = 0; i < 10; i++)
        {
            int tmp;
            scanf("%d", &tmp);
            if(tmp > left) left =tmp;
            else if(tmp > right) right = tmp;
            else flag = 1;
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

void solve()
{
    int arr[10];
    for (int i = 0; i < 10; ++i)
        cin >> arr[i];
    bool f = false;
    for (int bit = 0; bit < (1 << 10); ++bit)
    {
        bool judge = true;
        vector<int> v1, v2;
        for (int i = 0; i < 10; ++i)
        {
            if (bit >> i & 1)
                v1.push_back(arr[i]);
            else
                v2.push_back(arr[i]);
        }

        int n = v1.size();
        int m = v2.size();
        for (int i = 0; i < n - 1; ++i)
        {
            if (v1[i] < v1[i + 1])
                continue;
            else
                judge = false;
        }

        for (int i = 0; i < m - 1; ++i)
        {
            if (v2[i] < v2[i + 1])
                continue;
            else
                judge = false;
        }

        if (judge)
        {
            f = judge;
            break;
        }
    }
    if (f)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);

    int n;
    cin >> n;
    while (n--)
    {
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num, ans = 0; cin >> num;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            if(!push(input)) ans--;
        }
        if(ans == 0) cout << "YES" << endl;
        else if(ans < 0) cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
using namespace std;
int main(){
  int b[111],c[111];
  int i,j;
  int a,n;
  int w=0,q=0;
  int x=0,y=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(j%2==0){
	b[x]=a;
	if(x==0){
	  x++;
	  continue;
	}
	if(b[x]>b[x-1]){
	  w++;
	}
	x++;
      }
      else{
	c[y]=a;
	if(y==0){
	  y++;
	  continue;
	}
	if(c[y]>c[y-1]){
	  q++;
	}
	y++;
      }
    }
    if(w>=4 && q>=4){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
    w=0;
    q=0;
    x=0;
    y=0;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

int x[15],lside[15],rside[15];
int n,kase;

void dfs(int i,int l,int r){
	if(i > 10){
		kase = 1;
		return ;	
	}
	if(kase)	return ;
	if(x[i]>lside[l]){
		lside[l+1] = x[i];
		dfs(i+1,l+1,r);
	}
	if(x[i]>rside[r]){
		rside[r+1] = x[i];
		dfs(i+1,l,r+1);
	}
}
int main(void){
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)
			cin>>x[i];
		kase = 0;
		dfs(1,0,0);
		if(kase)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

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

int n;
int a[10];


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

void solve() {
    if (dfs(0,a[0],a[0])) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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