Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

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

  int ball_num = 10;
  for(int i=0;i<n;i++){
    vector<int> a;
    bool flag = true;
    for(int j=0;j<ball_num;j++){ 
      int tmp;
      cin >> tmp;
      a.push_back(tmp);
    }

    int b=0;
    int c=0;
    for(int i=0;i<ball_num;i++){
      if(b<=c){
	swap(b, c);
      }
      
      // b > c

      if(b < a[i]){
	b = a[i];
      }else{
	if(c < a[i]){
	  c = a[i];
	}else{
	  flag = false;
	}
      }

      if(flag==false){
	break;
      }
    }

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

  

}

C++: #include<iostream>

using namespace std;

int balls[15];

bool dfs(int ball_index, int right, int left) {
    if (ball_index == 10) return true;

    int last_ball = balls[ball_index];
    if (last_ball > right) return dfs(ball_index+1, last_ball, left);
    if (last_ball > left)  return dfs(ball_index+1, right, last_ball);

    return false;
}

void solve() {
    for (int i = 0; i < 10; i++) {
        cin >> balls[i];
    }

    if (dfs(0, 0, 0)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main(int argc, char const* argv[]) {

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        solve();
    }

    return 0;
}

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

using namespace std;

vector<int> nums;
int h, w;

bool dfs(int idx, int x, int y) {
	if (idx == 10) {
		return true;
	}
	bool ok = false;
	int z = nums[idx];
	if (x < z) {
		ok = dfs(idx + 1, z, y);
		if (ok) {
			return true;
		}
	}
	if (y < z) {
		ok = dfs(idx + 1, x, z);
		if (ok) {
			return true;
		}
	}

	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		nums.assign(10, 0);
		for (int j = 0; j < 10; j++) {
			cin >> nums[j];
		}
		bool ok = dfs(0, -1, -1);
		cout << (ok ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: /*
input:
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
output:
YES
NO
*/

#include <cstdio>

//&#36755;入
int a[10];

//深度&#20248;先放第K个球
bool dfs(int k, int B, int C){
	//若10个球都放完
	if(k == 10) return true;
	if(a[k] > B){
		//能放&#36827;B道
		if(dfs(k + 1, a[k], C))
			return true;
	}
	if(a[k] > C){
		//能放&#36827;C道
		if(dfs(k + 1, B, a[k]))
			return true;
	}
	//都不能放
	return false;
}

void solve(){
	if(dfs(0, 0, 0))
		printf("YES\n");
	else
		printf("NO\n");
}

int main(int argc, char const *argv[]){

	int t;
	scanf("%d", &t);
	while(t --){
		for(int i = 0; i < 10; i ++)
			scanf("%d", &a[i]);
		solve();
	}

	return 0;
}

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; }