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 bfs(int, int, int);
int a[11];
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 < 10; i2++){
			cin >> a[i2];
		}
		a[10] = 0;
		int ans=bfs(0, 0, 0);
		if (ans == 0){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" << endl;
		}
	}
	
}
int bfs(int i, int l, int r){
	int ans = 0;
	if (i == 10){
		ans = 1;
	}
	if (l < a[i]){
		ans = bfs(i + 1, a[i], r);
	}
	if (r < a[i]){
		ans = bfs(i + 1, l, a[i]);
	}
	return ans;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);
            if(pre > current){
				if(second_pre == -1){
					second_pre = current;
				}else{
					if(second_pre > current){
						NO_FLG = true;
						break;
					}else{
						second_pre = current;
					}
				}
			}else{
				pre = current;
			}
        }
        if(NO_FLG==false){
        	printf("YES\n");
        }else{
        	printf("NO\n");
        }
    }
    return 0;
}

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


int main(void){
    int n;
    int ball;
    int B_last, C_last;
    bool flag;
    cin>>n;
    vector<int> B(1,0);
    vector<int> C(1,0);
    for(int i=0;i<n;i++){
        flag=true;

        for(int j=0;j<10;j++){
            cin>>ball;
            B_last=B[B.size()-1];
            C_last=C[C.size()-1];
            if(B_last>=C_last){
                if(ball>B_last){
                    B.push_back(ball);
                }
                else if(ball>C_last){
                    C.push_back(ball);
                }
                else{
                    flag=false;
                }
            }
            else{
                if(ball>C_last){
                    C.push_back(ball);
                }
                else if(ball>B_last){
                    B.push_back(ball);
                }
                else{
                    flag=false;
                }
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
        B.clear();
        C.clear();
        B.push_back(0);
        C.push_back(0);
    }
    return 0;
}

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

int main(){
	
	
	int n;
	int b[10];
	
	cin>>n;
	while(n>0){
		stack<int> s1,s2;
		int f=0;
		for(int i=0;i<10;i++)
			cin>>b[i];
		for(int i=0;i<10;i++){
			if(s1.empty())
			s1.push(b[i]);
			else if(s1.top()<b[i])
			s1.push(b[i]);
			else if(s2.empty())
			s2.push(b[i]);
			else if(s2.top()<b[i])
			s2.push(b[i]);
			else
				f=1;
		}
		if(f==0)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
		n--;
			
	}
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      if(x>right){
        right = x;
      }else if(x>left){
        left = x;
      }else{
        flag = false;
        break;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

C++: #include<cstdio> #include<iostream> #include<stack> using namespace std;   stack<int> B; stack<int> C;   int A[10];   int solve(){     for(int i = 0;i<10;i++){         if(!B.empty()){             if(B.top()<A[i]){                 B.push(A[i]);             }else if(C.top()<A[i] || C.empty()){                 C.push(A[i]);             }else{                 return 0;             }         }else{             B.push(A[i]);             //cout<<B.top()<<endl;         }     }     return 1; }    int init(){     while(!B.empty())         B.pop();     while(!C.empty())         C.pop();     B.push(-1);     C.push(-1);  }    int main(void){     int n;     cin>>n;     for(int j = 0;j<n;j++){     init();     for(int i = 0;i<10;i++){         cin>>A[i];     }     if(solve()){         cout<<"YES"<<endl;     }else{         cout<<"NO"<<endl;     }     }     return 0; }

C++: #include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	int a[11];
	int flag;
	int b=0,c=0;
	while(n--)
	{
		flag=1;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				if(a[i]>b)
				{
					b=a[i];
				}
				else if(a[i]>c)
				{
					c=a[i];
				}
				else
				{
					flag=0;
				}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
 return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){

  int n,i;
  cin >> n;
  for(i=0;i<n;i++){
    int j;
    int tmp;
    int han=0;
    vector<int>in1;
    vector<int>in2;
    for(j=0;j<5;j++){
      cin >> tmp;
      in1.push_back(tmp);
      cin >> tmp;
      in2.push_back(tmp);
    }
    cout << in1[1] << endl;
    for(j=1;j<5;j++){
      if(in1[j-1]>in1[j])
	han=1;
      if(in2[j-1]>in2[j])
	han=1;
    }

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


}

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

int main()
{	
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int a, b = 0, c = 0;
		bool f = 1;
		for (int j = 0; j < 10; j++) {
			cin >> a;

			if (a > b && ((a > c && b >= c) || a < c))
				b = a;
			else if (a > c && ((a > b && b < c) || a < b))
				c = a;
			else {
				f = 0;
				break;
			}
		}

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

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> v(10);
    for (int j = 0; j < 10; j++) {
      cin >> v.at(j);
    }
    sort(v.begin(), v.begin() + 2);
    int a = v.at(0), b = v.at(1);
    bool flag = true;
    for (int k = 2; k < 10; k++) {
      if (v.at(k) > a) {
        if (v.at(k) < b) {
          a = v.at(k);
        } else {
          b = v.at(k);
        }
      } else {
        flag = false;
      }
    }
    if (flag)
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
  }
}